List of usage examples for org.apache.maven.project MavenProject getProperties
public Properties getProperties()
From source file:org.sourcepit.tpmp.resolver.tycho.TychoSessionTargetPlatformResolver.java
License:Apache License
private MavenProject setupAggregatedProject(MavenSession session, TargetPlatformConfiguration aggregatedConfiguration) { PropertiesMap mvnProperties = new LinkedPropertiesMap(); mvnProperties.load(getClass().getClassLoader(), "META-INF/tpmp/maven.properties"); String groupId = mvnProperties.get("groupId"); String artifactId = mvnProperties.get("artifactId"); String version = mvnProperties.get("version"); final String tpmpKey = Plugin.constructKey(groupId, artifactId); MavenProject origin = session.getCurrentProject(); Model model = origin.getModel().clone(); Build build = model.getBuild();//from w w w. j a v a 2s. c o m if (build.getPluginsAsMap().get(tpmpKey) == null) { Plugin tpmp = new Plugin(); tpmp.setGroupId(groupId); tpmp.setArtifactId(artifactId); tpmp.setVersion(version); build.getPlugins().add(tpmp); build.flushPluginMap(); } MavenProject fake = new MavenProject(model); fake.setClassRealm(origin.getClassRealm()); fake.setFile(origin.getFile()); final Map<String, ArtifactRepository> artifactRepositories = new LinkedHashMap<String, ArtifactRepository>(); final Map<String, ArtifactRepository> pluginRepositories = new LinkedHashMap<String, ArtifactRepository>(); for (MavenProject project : session.getProjects()) { for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) { if (!artifactRepositories.containsKey(repository.getId())) { artifactRepositories.put(repository.getId(), repository); } } for (ArtifactRepository repository : project.getPluginArtifactRepositories()) { if (!pluginRepositories.containsKey(repository.getId())) { pluginRepositories.put(repository.getId(), repository); } } } fake.setRemoteArtifactRepositories(new ArrayList<ArtifactRepository>(artifactRepositories.values())); fake.setPluginArtifactRepositories(new ArrayList<ArtifactRepository>(pluginRepositories.values())); fake.setManagedVersionMap(origin.getManagedVersionMap()); if (getTychoProject(fake) == null) { fake.setPackaging("eclipse-repository"); } fake.getBuildPlugins(); AbstractTychoProject tychoProject = (AbstractTychoProject) getTychoProject(fake); tychoProject.setupProject(session, fake); Properties properties = new Properties(); properties.putAll(fake.getProperties()); properties.putAll(session.getSystemProperties()); // session wins properties.putAll(session.getUserProperties()); fake.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties); fake.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, aggregatedConfiguration); ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger, aggregatedConfiguration.isResolveWithEEConstraints()); tychoProject.readExecutionEnvironmentConfiguration(fake, eeConfiguration); fake.setContextValue(TychoConstants.CTX_EXECUTION_ENVIRONMENT_CONFIGURATION, eeConfiguration); final DependencyMetadata dm = new DependencyMetadata(); for (ReactorProject reactorProject : DefaultReactorProject.adapt(session)) { mergeMetadata(dm, reactorProject, true); mergeMetadata(dm, reactorProject, false); } int i = 0; for (Object object : dm.getMetadata(true)) { InstallableUnitDAO dao = new TychoSourceIUResolver.InstallableUnitDAO( object.getClass().getClassLoader()); dao.setProperty(object, RepositoryLayoutHelper.PROP_CLASSIFIER, "fake_" + i); i++; } for (Object object : dm.getMetadata(false)) { InstallableUnitDAO dao = new TychoSourceIUResolver.InstallableUnitDAO( object.getClass().getClassLoader()); dao.setProperty(object, RepositoryLayoutHelper.PROP_CLASSIFIER, "fake_" + i); i++; } Map<String, DependencyMetadata> metadata = new LinkedHashMap<String, DependencyMetadata>(); metadata.put(null, dm); fake.setContextValue("tpmp.aggregatedMetadata", metadata); return fake; }
From source file:org.sourcepit.tpmp.ToolUtils.java
License:Apache License
public static String getTool(MavenSession session, MavenProject project) { final Properties properties = new Properties(); properties.putAll(project.getProperties()); properties.putAll(session.getSystemProperties()); // session wins properties.putAll(session.getUserProperties()); String tool = properties.getProperty("tpmp.tool"); if (tool == null) { tool = B2Utils.findModuleXML(session, project) == null ? "Tycho" : "b2"; }/*from ww w . j a va2 s. co m*/ return tool; }
From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java
License:Open Source License
public void interpolateModel(MavenProject project, Model model) throws MavenException { ModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setUserProperties(project.getProperties()); ModelProblemCollector problems = new ModelProblemCollector() { @Override/* w ww . j a va 2s .c o m*/ public void add(ModelProblemCollectorRequest req) { } }; lookup(ModelInterpolator.class).interpolateModel(model, project.getBasedir(), request, problems); }
From source file:org.srcdeps.mvn.enforcer.SrcdepsEnforcer.java
License:Apache License
@Override public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException { final MavenProject project = event.getProject(); log.info("srcdeps enforcer checks for violations in {}:{}", project.getGroupId(), project.getArtifactId()); final Maven maven = configurationProducer.getConfiguration().getMaven(); final List<MojoExecution> mojoExecutions = event.getExecutionPlan(); final List<String> goals = new ArrayList<>(mojoExecutions.size()); for (MojoExecution mojoExecution : mojoExecutions) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); goals.add(mojoDescriptor.getFullGoalName()); goals.add(mojoDescriptor.getGoal()); }// w ww .ja va 2 s. c o m final List<String> profiles = new ArrayList<>(); final List<Profile> activeProfiles = project.getActiveProfiles(); for (Profile profile : activeProfiles) { final String id = profile.getId(); profiles.add(id); } final Properties props = new Properties(); props.putAll(project.getProperties()); props.putAll(System.getProperties()); String[] firstViolation = assertFailWithout(maven.getFailWithout(), goals, profiles, props); if (firstViolation == null) { firstViolation = assertFailWith(maven.getFailWith(), goals, profiles, props); } if (firstViolation != null) { /* check if there are srcdeps */ Artifact parent = project.getParentArtifact(); if (parent != null) { assertNotSrcdeps(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), firstViolation); } DependencyManagement dm; List<Dependency> deps; if ((dm = project.getDependencyManagement()) != null && (deps = dm.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } if ((deps = project.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } } }
From source file:org.universAAL.maven.treebuilder.DependencyTreeBuilder.java
License:Apache License
/** * Method extracts separatedGroupIds - a list of Maven groupIds which * artifacts are treated in a special way during tree recursion. It is * assumed that artifacts with these groupIds are separated into two * artifacts (two parts): one with "core" suffix; one with "osgi" suffix. * Each one is later referred to as the counterpart of the other one. * Artifact with "core" suffix not always has to be present. It is assumed * that if artifact with "osgi" suffix has a "core" counterpart than it is * always specified as its direct dependency. When an artifact with * separatedGroupId is encountered it is treated in the recurse method in * the following way:/*from w w w .jav a 2s . co m*/ * <ul> * <li>if it is "core" artifact and it is beginning of the method than * Exception is thrown ("core" artifact of separatedGroupId should be never * passed for recursion). * <li>if it is "osgi" artifact and it has its "core" counterpart, then this * "core" is simply recursed further but its also remember as artifact which * will be removed from final composite just before writing its contents to * target\artifact.composite * <li> * if it is "osgi" artifact and it has a dependency to artifact with * separatedGroupId and a "core" suffix, then such depedency is changed to * its "osgi" counterpart WITH THE SAME VERSION NUMBER. Therefore there is a * strong assumption that a separated artifact has always its "osgi" and * "core" parts in the same version!!!! * </ul> * * When tree is built, all dependencies referring to the "core" artifact are * changed into dependencies referring to the "osgi" artifact. * * @param project * Maven project from which separatedGroupIds will be extracted. * @return List of separatedGroupIds. */ private List<String> extractSeparatedGroupIds(final MavenProject project) { List<String> separatedGroupIds = new ArrayList<String>(); Properties properties = project.getProperties(); if (properties != null) { String separatedGroupIdsStr = properties.getProperty(PROP_SEPARATED_GROUP_IDS); if (separatedGroupIdsStr != null) { for (String groupId : separatedGroupIdsStr.split(",")) { separatedGroupIds.add(groupId.trim()); } } } return separatedGroupIds; }
From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java
License:Apache License
public static String replaceProperties(MavenProject mavenProject, String s) { String prop = s.replaceAll("\\$\\{(.*)\\}", "$1"); return mavenProject.getProperties().getProperty(prop); }
From source file:org.universAAL.support.directives.checks.MavenCoordinateCheck.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException { String artifactIdMatchString = mavenProject.getProperties().getProperty(ARTIFACT_ID_MATCH_PROP, DEFAULT_MATCH);/*from w w w. j a va 2 s .co m*/ String groupIdMatchString = mavenProject.getProperties().getProperty(GROUP_ID_MATCH_PROP, DEFAULT_MATCH); String nameMatchString = mavenProject.getProperties().getProperty(NAME_MATCH_PROP, DEFAULT_MATCH); String versionMatchString = mavenProject.getProperties().getProperty(VERSION_MATCH_PROP, DEFAULT_MATCH); Pattern pAId = Pattern.compile(artifactIdMatchString); Pattern pGId = Pattern.compile(groupIdMatchString); Pattern pVer = Pattern.compile(versionMatchString); Pattern pNam = Pattern.compile(nameMatchString); Matcher mAId = pAId.matcher(mavenProject.getArtifactId()); Matcher mGId = pGId.matcher(mavenProject.getGroupId()); Matcher mVer = pVer.matcher(mavenProject.getVersion()); Matcher mNam = pNam.matcher(mavenProject.getName()); StringBuffer message = new StringBuffer(); if (!mAId.find()) { message.append("ArtifactId: " + mavenProject.getArtifactId() + DOES_NOT_MATCH_CONVENTION + artifactIdMatchString + "\n"); } if (!mGId.find()) { message.append("GroupId: " + mavenProject.getGroupId() + DOES_NOT_MATCH_CONVENTION + groupIdMatchString + "\n"); } if (!mVer.find()) { message.append("Version: " + mavenProject.getVersion() + DOES_NOT_MATCH_CONVENTION + versionMatchString + "\n"); } if (!mNam.find()) { message.append("Artifact Name: " + mavenProject.getName() + DOES_NOT_MATCH_CONVENTION + nameMatchString + "\n"); } if (message.length() > 0) { throw new MojoFailureException(message.toString()); } Model pomFileModel = null; try { pomFileModel = PomWriter.readPOMFile(mavenProject); } catch (Exception e) { } if (!mavenProject.getPackaging().equals("pom") && pomFileModel != null && (pomFileModel.getProperties().containsKey(ARTIFACT_ID_MATCH_PROP) || pomFileModel.getProperties().containsKey(GROUP_ID_MATCH_PROP) || pomFileModel.getProperties().containsKey(VERSION_MATCH_PROP) || pomFileModel.getProperties().containsKey(NAME_MATCH_PROP))) { throw new MojoFailureException("This project has declared naming conventions when it shoudln't.\n" + "This is probably an attempt to skip this directive, SHAME ON YOU!"); } return true; }
From source file:org.universAAL.support.directives.checks.ParentGForgePropertyCheck.java
License:Apache License
public static boolean hasProperty(MavenProject mp, String prop) { return mp.getProperties().containsKey(prop); }
From source file:org.vafer.jdeb.maven.DebMojo.java
License:Apache License
/** * Main entry point/*from w w w . ja v a 2 s .c o m*/ * * @throws MojoExecutionException on error */ @Override public void execute() throws MojoExecutionException { final MavenProject project = getProject(); if (skip) { getLog().info("skipping as configured (skip)"); return; } if (skipPOMs && isPOM()) { getLog().info("skipping because artifact is a pom (skipPOMs)"); return; } if (skipSubmodules && isSubmodule()) { getLog().info("skipping submodule (skipSubmodules)"); return; } setData(dataSet); console = new MojoConsole(getLog(), verbose); initializeSignProperties(); final VariableResolver resolver = initializeVariableResolver(new HashMap<String, String>()); final File debFile = new File(Utils.replaceVariables(resolver, deb, openReplaceToken, closeReplaceToken)); final File controlDirFile = new File( Utils.replaceVariables(resolver, controlDir, openReplaceToken, closeReplaceToken)); final File installDirFile = new File( Utils.replaceVariables(resolver, installDir, openReplaceToken, closeReplaceToken)); final File changesInFile = new File( Utils.replaceVariables(resolver, changesIn, openReplaceToken, closeReplaceToken)); final File changesOutFile = new File( Utils.replaceVariables(resolver, changesOut, openReplaceToken, closeReplaceToken)); final File changesSaveFile = new File( Utils.replaceVariables(resolver, changesSave, openReplaceToken, closeReplaceToken)); final File keyringFile = keyring == null ? null : new File(Utils.replaceVariables(resolver, keyring, openReplaceToken, closeReplaceToken)); // if there are no producers defined we try to use the artifacts if (dataProducers.isEmpty()) { if (hasMainArtifact()) { Set<Artifact> artifacts = new HashSet<Artifact>(); artifacts.add(project.getArtifact()); @SuppressWarnings("unchecked") final Set<Artifact> projectArtifacts = project.getArtifacts(); for (Artifact artifact : projectArtifacts) { artifacts.add(artifact); } @SuppressWarnings("unchecked") final List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); for (Artifact artifact : attachedArtifacts) { artifacts.add(artifact); } for (Artifact artifact : artifacts) { final File file = artifact.getFile(); if (file != null) { dataProducers.add(new DataProducer() { @Override public void produce(final DataConsumer receiver) { try { final File path = new File(installDirFile.getPath(), file.getName()); final String entryName = path.getPath(); final boolean symbolicLink = SymlinkUtils.isSymbolicLink(path); final TarArchiveEntry e; if (symbolicLink) { e = new TarArchiveEntry(entryName, TarConstants.LF_SYMLINK); e.setLinkName(SymlinkUtils.readSymbolicLink(path)); } else { e = new TarArchiveEntry(entryName, true); } e.setUserId(0); e.setGroupId(0); e.setUserName("root"); e.setGroupName("root"); e.setMode(TarEntry.DEFAULT_FILE_MODE); e.setSize(file.length()); receiver.onEachFile(new FileInputStream(file), e); } catch (Exception e) { getLog().error(e); } } }); } else { getLog().error("No file for artifact " + artifact); } } } } try { DebMaker debMaker = new DebMaker(console, dataProducers, conffileProducers); debMaker.setDeb(debFile); debMaker.setControl(controlDirFile); debMaker.setPackage(getProject().getArtifactId()); debMaker.setDescription(getProject().getDescription()); debMaker.setHomepage(getProject().getUrl()); debMaker.setChangesIn(changesInFile); debMaker.setChangesOut(changesOutFile); debMaker.setChangesSave(changesSaveFile); debMaker.setCompression(compression); debMaker.setKeyring(keyringFile); debMaker.setKey(key); debMaker.setPassphrase(passphrase); debMaker.setSignPackage(signPackage); debMaker.setSignMethod(signMethod); debMaker.setSignRole(signRole); debMaker.setResolver(resolver); debMaker.setOpenReplaceToken(openReplaceToken); debMaker.setCloseReplaceToken(closeReplaceToken); debMaker.validate(); debMaker.makeDeb(); // Always attach unless explicitly set to false if ("true".equalsIgnoreCase(attach)) { console.info("Attaching created debian package " + debFile); if (!isType()) { projectHelper.attachArtifact(project, type, classifier, debFile); } else { project.getArtifact().setFile(debFile); } } } catch (PackagingException e) { getLog().error("Failed to create debian package " + debFile, e); throw new MojoExecutionException("Failed to create debian package " + debFile, e); } if (!isBlank(propertyPrefix)) { project.getProperties().put(propertyPrefix + "version", getProjectVersion()); project.getProperties().put(propertyPrefix + "deb", debFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "deb.name", debFile.getName()); project.getProperties().put(propertyPrefix + "changes", changesOutFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "changes.name", changesOutFile.getName()); project.getProperties().put(propertyPrefix + "changes.txt", changesSaveFile.getAbsolutePath()); project.getProperties().put(propertyPrefix + "changes.txt.name", changesSaveFile.getName()); } }
From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaLibraryUtil.java
License:Open Source License
private static String resolveMavenProperty(MavenProject project, String property) { if (project.getProperties().containsKey(property)) { return project.getProperties().getProperty(property, property); }//from w w w .j a v a2s . c o m return "${" + property + "}"; }