List of usage examples for org.apache.maven.artifact.versioning DefaultArtifactVersion toString
@Override
public String toString()
From source file:com.cloudera.whirr.cm.server.impl.CmServerImpl.java
License:Apache License
private void provisionParcels(final CmServerCluster cluster) throws InterruptedException, IOException { apiResourceRootV3.getClouderaManagerResource().updateConfig( new ApiConfigList(Arrays.asList(new ApiConfig[] { new ApiConfig("PARCEL_UPDATE_FREQ", "1") }))); final Set<String> repositoriesRequired = new HashSet<String>(); for (CmServerServiceType type : cluster.getServiceTypes(versionApi, versionCdh)) { repositoriesRequired.add(type.getRepository().toString(CDH_REPO_PREFIX + versionCdh)); }/*from w w w. j av a 2s. c o m*/ final List<String> repositoriesRequiredOrdered = new ArrayList<String>(); for (String repository : repositoriesRequired) { if (repository.equals(CDH_REPO_PREFIX)) { repositoriesRequiredOrdered.add(0, repository); } else { repositoriesRequiredOrdered.add(repository); } } execute("WaitForParcelsAvailability", new Callback() { @Override public boolean poll() { for (ApiParcel parcel : apiResourceRootV3.getClustersResource().getParcelsResource(getName(cluster)) .readParcels(DataView.FULL).getParcels()) { try { repositoriesRequired.remove(parcel.getProduct()); } catch (IllegalArgumentException e) { // ignore } } return repositoriesRequired.isEmpty(); } }); apiResourceRootV3.getClouderaManagerResource().updateConfig( new ApiConfigList(Arrays.asList(new ApiConfig[] { new ApiConfig("PARCEL_UPDATE_FREQ", "60") }))); for (String repository : repositoriesRequiredOrdered) { DefaultArtifactVersion parcelVersion = null; for (ApiParcel apiParcel : apiResourceRootV3.getClustersResource().getParcelsResource(getName(cluster)) .readParcels(DataView.FULL).getParcels()) { DefaultArtifactVersion parcelVersionTmp = new DefaultArtifactVersion(apiParcel.getVersion()); if (apiParcel.getProduct().equals(repository)) { if (!apiParcel.getProduct().equals(CDH_REPO_PREFIX) || versionCdh == parcelVersionTmp.getMajorVersion()) { if (parcelVersion == null || parcelVersion.compareTo(parcelVersionTmp) < 0) { parcelVersion = new DefaultArtifactVersion(apiParcel.getVersion()); } } } } final ParcelResource apiParcelResource = apiResourceRootV3.getClustersResource() .getParcelsResource(getName(cluster)).getParcelResource(repository, parcelVersion.toString()); execute(apiParcelResource.startDownloadCommand(), new Callback() { @Override public boolean poll() { return apiParcelResource.readParcel().getStage().equals(CM_PARCEL_STAGE_DOWNLOADED); } }, false); execute(apiParcelResource.startDistributionCommand(), new Callback() { @Override public boolean poll() { return apiParcelResource.readParcel().getStage().equals(CM_PARCEL_STAGE_DISTRIBUTED); } }, false); execute(apiParcelResource.activateCommand(), new Callback() { @Override public boolean poll() { return apiParcelResource.readParcel().getStage().equals(CM_PARCEL_STAGE_ACTIVATED); } }, false); } }
From source file:com.github.panthers.maven.plugins.fromConfig.AbstractFromConfigMojo.java
License:Apache License
/** * For a given artifactItem with range this produces the list of artifactItems with available versions. * Versions are filtered based on configuration * Output file name is set as artifactId-version.type * @param artifactItemsWithRange// ww w .j ava2 s .c o m * @return * @throws MojoExecutionException */ protected List<ArtifactItem> getProcessRangedArtifactItems(ArtifactItemsWithRange artifactItemsWithRange) throws MojoExecutionException { getLog().debug(logArtifactWithRange(artifactItemsWithRange)); List<DefaultArtifactVersion> avilableVersions = getAvailableVersions(artifactItemsWithRange); List<ArtifactItem> artifactItems = new ArrayList<ArtifactItem>(); for (DefaultArtifactVersion av : avilableVersions) { Artifact artifactWithVersion; if (StringUtils.isEmpty(artifactItemsWithRange.getClassifier())) { artifactWithVersion = factory.createDependencyArtifact(artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), VersionRange.createFromVersion(av.toString()), artifactItemsWithRange.getType(), null, Artifact.SCOPE_COMPILE); } else { artifactWithVersion = factory.createDependencyArtifact(artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), VersionRange.createFromVersion(av.toString()), artifactItemsWithRange.getType(), artifactItemsWithRange.getClassifier(), Artifact.SCOPE_COMPILE); } artifactWithVersion = resolveArtifact(artifactWithVersion); ArtifactItem artifactItem = new ArtifactItem(artifactWithVersion); //Destination name is artifactId-version.type artifactItem.setDestFileName( artifactItem.getArtifactId() + "-" + artifactItem.getVersion() + "." + artifactItem.getType()); //First preference goes to artifactItem output directory if (artifactItemsWithRange.getOutputDirectory() == null) { artifactItem.setOutputDirectory(outputDirectory); } else { artifactItem.setOutputDirectory(artifactItemsWithRange.getOutputDirectory()); } artifactItem.getOutputDirectory().mkdir(); artifactItem.setOverWrite(artifactItemsWithRange.getOverWrite()); artifactItem.setNeedsProcessing(true); getLog().info( "Artifact : " + artifactItemsWithRange.getArtifactId() + " Found version : " + av.toString()); artifactItems.add(artifactItem); } return artifactItems; }
From source file:com.vmware.bdd.plugin.clouderamgr.service.ClouderaManagerImpl.java
License:Open Source License
/** provision parcels, Reentrant * A Parcel encapsulate a specific product and version. For example, (CDH 4.1). * A parcel is downloaded, distributed to all the machines of a cluster and then allowed to be activated. * * @param cluster/*from ww w . j a v a 2 s. c o m*/ * @param reportQueue * @throws Exception */ private void provisionParcels(final CmClusterDef cluster, final List<String> addedNodes, final ClusterReportQueue reportQueue) throws Exception { if (isConfigured(cluster)) { return; } apiResourceRootV6.getClouderaManagerResource().updateConfig( new ApiConfigList(Arrays.asList(new ApiConfig[] { new ApiConfig("PARCEL_UPDATE_FREQ", "1") }))); final Set<String> repositoriesRequired = new HashSet<String>(); for (CmServiceDef serviceDef : cluster.getServices()) { repositoriesRequired.add(serviceDef.getType().getRepository().toString(cluster.getVersion())); } logger.info("parcel repo required: " + repositoriesRequired + " cluster: " + cluster.getName()); final List<String> repositoriesRequiredOrdered = new ArrayList<String>(); for (String repository : repositoriesRequired) { if (repository.equals(Constants.CDH_REPO_PREFIX)) { repositoriesRequiredOrdered.add(0, repository); } else { repositoriesRequiredOrdered.add(repository); } } // validate this cluster has access to all Parcels it requires executeAndReport("Validating parcels availability", addedNodes, null, ProgressSplit.VALIDATE_PARCELS_AVAILABILITY.getProgress(), cluster.getCurrentReport(), reportQueue, new StatusPoller() { @Override public boolean poll() { for (ApiParcel parcel : apiResourceRootV6.getClustersResource() .getParcelsResource(cluster.getName()).readParcels(DataView.FULL).getParcels()) { try { repositoriesRequired.remove(parcel.getProduct()); } catch (IllegalArgumentException e) { // ignore } } // TODO: if one required parcel is not available, will run forever, need timeout/validation return repositoriesRequired.isEmpty(); } }, false); apiResourceRootV6.getClouderaManagerResource().updateConfig( new ApiConfigList(Arrays.asList(new ApiConfig[] { new ApiConfig("PARCEL_UPDATE_FREQ", "60") }))); DefaultArtifactVersion expectVersion = null; if (cluster.getFullVersion() != null) { expectVersion = new DefaultArtifactVersion(cluster.getFullVersion()); } for (String repository : repositoriesRequiredOrdered) { DefaultArtifactVersion parcelVersion = null; for (ApiParcel apiParcel : apiResourceRootV6.getClustersResource().getParcelsResource(cluster.getName()) .readParcels(DataView.FULL).getParcels()) { DefaultArtifactVersion parcelVersionTmp = new DefaultArtifactVersion(apiParcel.getVersion()); if (apiParcel.getProduct().equals(repository)) { if (apiParcel.getProduct().equals(Constants.CDH_REPO_PREFIX)) { /* * Policy for "CDH" parcel: * 1) If specify fullVersion, try to find that parcel, if cannot, select the latest parcel(with highest version). * 2) If fullVersion not specified, select the latest parcel */ if (parcelVersion == null || parcelVersion.compareTo(parcelVersionTmp) < 0) { parcelVersion = new DefaultArtifactVersion(apiParcel.getVersion()); } if (expectVersion != null && parcelVersionTmp.getMajorVersion() == expectVersion.getMajorVersion() && parcelVersionTmp.getMinorVersion() == expectVersion.getMinorVersion() && parcelVersionTmp.getIncrementalVersion() == expectVersion .getIncrementalVersion()) { parcelVersion = new DefaultArtifactVersion(apiParcel.getVersion()); break; } } if (!apiParcel.getProduct().equals(Constants.CDH_REPO_PREFIX)) { // For non-CDH parcel, just select the latest one if (parcelVersion == null || parcelVersion.compareTo(parcelVersionTmp) < 0) { parcelVersion = new DefaultArtifactVersion(apiParcel.getVersion()); } } } } final ParcelResource apiParcelResource = apiResourceRootV6.getClustersResource() .getParcelsResource(cluster.getName()).getParcelResource(repository, parcelVersion.toString()); String refMsg = referCmfUrlMsg(domain + "/cmf/parcel/status"); if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.DOWNLOADED.ordinal()) { String action = "Downloading parcel..."; ParcelProvisionPoller poll = new ParcelProvisionPoller(apiParcelResource, AvailableParcelStage.DOWNLOADED, cluster.getCurrentReport(), reportQueue, ProgressSplit.DOWNLOAD_PARCEL.getProgress()); if (apiParcelResource.readParcel().getStage().equals(AvailableParcelStage.DOWNLOADING.toString())) { // Another thread is downloading this parcel, just wait for its completion executeAndReport(action, null, ProgressSplit.DOWNLOAD_PARCEL.getProgress(), cluster.getCurrentReport(), reportQueue, poll, false); } else { // the ApiCommand instance for parcel is inaccessible, so do not check the return value executeAndReport(action, apiParcelResource.startDownloadCommand(), ProgressSplit.DOWNLOAD_PARCEL.getProgress(), cluster.getCurrentReport(), reportQueue, poll, false); } if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.DOWNLOADED.ordinal()) { throw ClouderaManagerException.DOWNLOAD_PARCEL_FAIL(apiParcelResource.readParcel().getProduct(), apiParcelResource.readParcel().getVersion(), refMsg); } } if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.DISTRIBUTED.ordinal()) { String action = "Distributing parcel..."; final StatusPoller poller = new ParcelProvisionPoller(apiParcelResource, AvailableParcelStage.DISTRIBUTED, cluster.getCurrentReport(), reportQueue, ProgressSplit.DISTRIBUTE_PARCEL.getProgress()); executeAndReport(action, apiParcelResource.startDistributionCommand(), ProgressSplit.DISTRIBUTE_PARCEL.getProgress(), cluster.getCurrentReport(), reportQueue, poller, false); if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.DISTRIBUTED.ordinal()) { throw ClouderaManagerException.DISTRIBUTE_PARCEL_FAIL( apiParcelResource.readParcel().getProduct(), apiParcelResource.readParcel().getVersion(), refMsg); } } if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.ACTIVATED.ordinal()) { String action = "Activating parcel..."; executeAndReport(action, apiParcelResource.activateCommand(), ProgressSplit.ACTIVATE_PARCEL.getProgress(), cluster.getCurrentReport(), reportQueue, new StatusPoller() { @Override public boolean poll() { // activate parcel is pretty fast, so suppose we are no need to do much error handling/progress monitoring // TODO: set a timeout return apiParcelResource.readParcel().getStage() .equals(AvailableParcelStage.ACTIVATED.toString()); } }, false); if (AvailableParcelStage.valueOf(apiParcelResource.readParcel().getStage()) .ordinal() < AvailableParcelStage.ACTIVATED.ordinal()) { throw ClouderaManagerException.ACTIVATE_PARCEL_FAIL(apiParcelResource.readParcel().getProduct(), apiParcelResource.readParcel().getVersion(), refMsg); } } } }
From source file:io.wcm.devops.conga.tooling.maven.plugin.ValidateVersionInfoMojo.java
License:Apache License
private void validateVersionInfo(Properties currentVersionInfo, Properties dependencyVersionInfo) throws MojoExecutionException { for (Object keyObject : currentVersionInfo.keySet()) { String key = keyObject.toString(); String currentVersionString = currentVersionInfo.getProperty(key); String dependencyVersionString = dependencyVersionInfo.getProperty(key); if (StringUtils.isEmpty(currentVersionString) || StringUtils.isEmpty(dependencyVersionString)) { continue; }/*from w w w .jav a 2 s. com*/ DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(currentVersionString); DefaultArtifactVersion dependencyVersion = new DefaultArtifactVersion(dependencyVersionString); if (currentVersion.compareTo(dependencyVersion) < 0) { throw new MojoExecutionException("Newer CONGA maven plugin or plugin version required: " + key + ":" + dependencyVersion.toString()); } } }
From source file:name.richardson.james.bukkit.utilities.updater.AbstractPluginUpdater.java
License:Open Source License
public boolean isNewVersionAvailable() { final DefaultArtifactVersion current = new DefaultArtifactVersion(getLocalVersion()); final DefaultArtifactVersion target = new DefaultArtifactVersion(getRemoteVersion()); final Object params[] = { target.toString(), current.toString() }; if (current.compareTo(target) == -1) { this.logger.log(Level.FINE, "New version available: {0} > {1}", params); return true; } else {//from ww w .jav a 2 s . co m return false; } }
From source file:org.bimserver.version.VersionChecker.java
License:Open Source License
public VersionChecker(ResourceFetcher resourceFetcher) throws VersionCheckException { try {/*from w w w . j ava 2 s. c o m*/ Path pom = resourceFetcher.getFile("pom.xml"); if (pom == null) { throw new VersionCheckException("No pom.xml found"); } if (Files.exists(pom)) { String version = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); if (pom != null) { try (FileReader fileReader = new FileReader(pom.toFile())) { Model model = mavenreader.read(fileReader); version = model.getVersion(); } } if (version == null) { // Only on development environments we have to get the version from the parent pom file Path parentPom = resourceFetcher.getFile("../pom.xml"); if (parentPom != null) { try (FileReader fileReader = new FileReader(parentPom.toFile())) { Model parentModel = mavenreader.read(fileReader); version = parentModel.getVersion(); } } else { LOGGER.error("No parent pom.xml found"); } } DefaultArtifactVersion defaultArtifactVersion = new DefaultArtifactVersion(version); localVersion = new SVersion(); localVersion.setMajor(defaultArtifactVersion.getMajorVersion()); localVersion.setMinor(defaultArtifactVersion.getMinorVersion()); localVersion.setRevision(defaultArtifactVersion.getIncrementalVersion()); localVersion.setFullString(defaultArtifactVersion.toString()); } else { LOGGER.warn("No version info"); } } catch (Exception e) { throw new VersionCheckException(e); } }
From source file:org.codehaus.mojo.VeraxxMojo.java
License:Apache License
protected void preExecute(Executor exec, CommandLine commandLine, Map enviro) throws MojoExecutionException { OutputStream outStream = /*System.out;*/new ByteArrayOutputStream(); OutputStream errStream = new ByteArrayOutputStream(); CommandLine commandLineCheck = new CommandLine(getExecutable()); Executor execCheck = new DefaultExecutor(); String[] args = parseCommandlineArgs("--version"); commandLineCheck.addArguments(args, false); execCheck.setWorkingDirectory(exec.getWorkingDirectory()); getLog().info("Executing command line: " + commandLineCheck); int res = 0;/* ww w.j a v a 2s . c o m*/ try { res = executeCommandLine(execCheck, commandLineCheck, enviro, outStream/*getOutputStreamOut()*/, errStream/*getOutputStreamErr()*/, getInputStream()); } catch (ExecuteException e) { getLog().info( "Exec Exception while detecting Vera++ version. Assume old Vera++ v1.1.x (and less) output parsing style"); getLog().info("Vera++ err output is : " + errStream.toString()); veraxx_version = 0; /*throw new MojoExecutionException( "preExecute Command execution failed.", e );*/ return; } catch (IOException e) { getLog().info("Vera++ detected version is : " + outStream.toString()); getLog().info("Vera++ err output is : " + errStream.toString()); // due to jdk8 bug :: https://bugs.openjdk.java.net/browse/JDK-8054565 // we use this dirty try/catch ... // because this quick command line call can close the output stream before jvm does getLog().info("jvm " + System.getProperty("java.version") + " (8u11 - 9) workaround, ignoring a " + e.toString() + " during vera++ test command line."); //throw new MojoExecutionException( "preExecute Command execution failed.", e ); } if (isResultCodeAFailure(res)) { getLog().info("Vera++ returned a failure result code : " + res); //throw new MojoExecutionException( "preExecute Result of " + commandLineCheck + " execution is: '" + res + "'." ); } DefaultArtifactVersion newFormatMinVersion = new DefaultArtifactVersion("1.2.0"); DefaultArtifactVersion currentVeraVersion = new DefaultArtifactVersion(outStream.toString()); getLog().debug("Vera++ detected version is : " + outStream.toString()); getLog().debug("Vera++ version as ArtefactVersion is : " + currentVeraVersion.toString()); if (currentVeraVersion.compareTo(newFormatMinVersion) < 0) { getLog().info("Use old Vera++ v1.1.x (and less) output parsing style"); veraxx_version = 0; } else { getLog().info("Use Vera++ v1.2.0 (and more) output parsing style"); veraxx_version = 1; } }