in taverna-maven-plugin/src/main/java/org/apache/taverna/mavenplugin/TavernaProfileDeployMojo.java [59:200]
public void execute() throws MojoExecutionException {
tempDirectory = new File(buildDirectory, TavernaProfileGenerateMojo.TAVERNA_TMP);
tempDirectory.mkdirs();
if (artifact == null) {
throw new MojoExecutionException(
"The application profile does not exist, please run taverna:profile-generate first");
}
File artifactFile = artifact.getFile();
if (artifactFile == null) {
throw new MojoExecutionException(
"The application profile does not exist, please run taverna:profile-generate first");
}
JAXBContext jaxbContext;
try {
jaxbContext = JAXBContext.newInstance(ApplicationProfile.class, UpdateSite.class);
} catch (JAXBException e) {
throw new MojoExecutionException("Error setting up JAXB context ", e);
}
ApplicationProfile applicationProfile;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
applicationProfile = (ApplicationProfile) unmarshaller.unmarshal(artifactFile);
} catch (JAXBException e) {
throw new MojoExecutionException("Error reading " + artifactFile, e);
}
if (deploymentRepository == null) {
throw new MojoExecutionException(
"Missing repository information in the distribution management element in the project.");
}
String url = deploymentRepository.getUrl();
String id = deploymentRepository.getId();
if (url == null) {
throw new MojoExecutionException(
"The URL to the update site is missing in the project descriptor.");
}
getLog().debug("The Taverna application will be deployed to '" + url + "'");
Repository repository = new Repository(id, url);
// create the wagon
Wagon wagon;
try {
wagon = wagonManager.getWagon(repository.getProtocol());
} catch (UnsupportedProtocolException e) {
throw new MojoExecutionException("Unsupported protocol: '" + repository.getProtocol()
+ "'", e);
}
Debug debug = new Debug();
if (getLog().isDebugEnabled()) {
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
}
// connect to the update site
try {
wagon.connect(repository, wagonManager.getAuthenticationInfo(id),
wagonManager.getProxy(repository.getProtocol()));
} catch (ConnectionException e) {
throw new MojoExecutionException("Error connecting to " + url, e);
} catch (AuthenticationException e) {
throw new MojoExecutionException("Authentication error connecting to " + url, e);
}
try {
// upload the application profile to the update site
String deployedProfileFile = "ApplicationProfile" + "-" + applicationProfile.getVersion()
+ ".xml";
Utils.uploadFile(artifactFile, deployedProfileFile, wagon, getLog());
// fetch the applications file
UpdateSite updateSite;
File updatesFile = new File(tempDirectory, UPDATES_FILE);
try {
Utils.downloadFile(UPDATES_FILE, updatesFile, wagon, getLog());
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
updateSite = (UpdateSite) unmarshaller
.unmarshal(updatesFile);
} catch (JAXBException e) {
throw new MojoExecutionException("Error reading " + updatesFile, e);
}
} catch(ResourceDoesNotExistException e) {
getLog().info("Creating new application versions file");
updateSite = new UpdateSite();
Versions versions = new Versions();
versions.setId(applicationProfile.getId());
versions.setName(applicationProfile.getName());
updateSite.setVersions(versions);
}
Version latestVersion = updateSite.getVersions().getLatestVersion();
if (latestVersion != null) {
File latestProfileFile = new File(tempDirectory, "ApplicationProfile-" + latestVersion.getVersion()
+ ".xml");
try {
Utils.downloadFile(latestVersion.getFile(), latestProfileFile, wagon, getLog());
} catch (ResourceDoesNotExistException e) {
throw new MojoExecutionException(latestVersion.getFile() + " does not exist", e);
}
ApplicationProfile latestProfile;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
latestProfile = (ApplicationProfile) unmarshaller.unmarshal(latestProfileFile);
} catch (JAXBException e) {
throw new MojoExecutionException("Error reading " + latestProfileFile, e);
}
Set<BundleInfo> requiredBundles = getRequiredBundles(latestProfile, applicationProfile);
if (requiredBundles.isEmpty()) {
getLog().warn("No new bundles to upload");
} else {
// upload new bundles to the update site
uploadBundles(requiredBundles, wagon);
}
}
if (addApplicationVersion(updateSite.getVersions(), applicationProfile,
deployedProfileFile)) {
// write the new application versions list
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, TavernaProfileGenerateMojo.SCHEMA_LOCATION);
marshaller.marshal(updateSite, updatesFile);
} catch (JAXBException e) {
throw new MojoExecutionException("Error writing " + UPDATES_FILE, e);
}
// upload the new application versions list to the update site
Utils.uploadFile(updatesFile, UPDATES_FILE, wagon, getLog());
}
}
finally {
disconnectWagon(wagon, debug);
}
}