private static String determineNewestVersion( RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository>[] repos) throws MojoExecutionException { String version; VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)")); for (List<RemoteRepository> repoList : repos) { for (RemoteRepository repo : repoList) { rangeRequest.addRepository(repo); } } VersionRangeResult rangeResult; try { rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest); } catch (VersionRangeResolutionException e) { throw new MojoExecutionException( "Could not resolve latest version of the App Engine Java SDK", e); } List<Version> versions = rangeResult.getVersions(); Collections.sort(versions); Version newest = Iterables.getLast(versions); version = newest.toString(); return version; }
@Override public <T> List<T> getData(String key, Class<T> type, Object... params) { List<T> retval = null; if ("profileIds".equals(key)) { final List<T> profileIds = new ArrayList<T>(); try { final List<Profile> profiles = MavenPlugin.getMaven().getSettings().getProfiles(); for (final Profile profile : profiles) { if (profile.getActivation() != null) { if (profile.getActivation().isActiveByDefault()) { continue; } } profileIds.add(type.cast(profile.getId())); } if (params[0] != null && params[0] instanceof File) { final File locationDir = (File) params[0]; File pomFile = new File(locationDir, IMavenConstants.POM_FILE_NAME); if (!pomFile.exists() && locationDir.getParentFile().exists()) { // try one level up for when user is adding new module pomFile = new File(locationDir.getParentFile(), IMavenConstants.POM_FILE_NAME); } if (pomFile.exists()) { final IMaven maven = MavenPlugin.getMaven(); Model model = maven.readModel(pomFile); File parentDir = pomFile.getParentFile(); while (model != null) { for (org.apache.maven.model.Profile p : model.getProfiles()) { profileIds.add(type.cast(p.getId())); } parentDir = parentDir.getParentFile(); if (parentDir != null && parentDir.exists()) { try { model = maven.readModel(new File(parentDir, IMavenConstants.POM_FILE_NAME)); } catch (Exception e) { model = null; } } } } } } catch (CoreException e) { LiferayMavenCore.logError(e); } retval = profileIds; } else if ("liferayVersions".equals(key)) { final List<T> possibleVersions = new ArrayList<T>(); final RepositorySystem system = AetherUtil.newRepositorySystem(); final RepositorySystemSession session = AetherUtil.newRepositorySystemSession(system); final String groupId = params[0].toString(); final String artifactId = params[1].toString(); final String coords = groupId + ":" + artifactId + ":[6,)"; final Artifact artifact = new DefaultArtifact(coords); final VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifact); rangeRequest.addRepository(AetherUtil.newCentralRepository()); rangeRequest.addRepository(AetherUtil.newLiferayRepository()); try { final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); final List<Version> versions = rangeResult.getVersions(); for (Version version : versions) { final String val = version.toString(); if (!"6.2.0".equals(val)) { possibleVersions.add(type.cast(val)); } } retval = possibleVersions; } catch (VersionRangeResolutionException e) { } } else if ("parentVersion".equals(key)) { final List<T> version = new ArrayList<T>(); final File locationDir = (File) params[0]; final File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME); if (parentPom.exists()) { try { final IMaven maven = MavenPlugin.getMaven(); final Model model = maven.readModel(parentPom); version.add(type.cast(model.getVersion())); retval = version; } catch (CoreException e) { LiferayMavenCore.logError("unable to get parent version", e); } } } else if ("parentGroupId".equals(key)) { final List<T> groupId = new ArrayList<T>(); final File locationDir = (File) params[0]; final File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME); if (parentPom.exists()) { try { final IMaven maven = MavenPlugin.getMaven(); final Model model = maven.readModel(parentPom); groupId.add(type.cast(model.getGroupId())); retval = groupId; } catch (CoreException e) { LiferayMavenCore.logError("unable to get parent groupId", e); } } } return retval; }