List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
@Override public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException { this.log.info("Perform replacement in POMs."); // prepare for rollback this.cachedPOMs = Maps.newHashMap(); for (MavenProject p : this.reactorProjects) { this.cachedPOMs.put(p, PomUtil.parsePOM(p).get()); }/*w w w. j a v a 2 s. co m*/ // retrieve qualifier (for instance the 1 in genericReplacer[1]) String _qualifier = context.getQualifier() != null ? context.getQualifier() : "1"; String _signGPG = "false"; if (_qualifier.contains(",")) { _signGPG = _qualifier.substring(_qualifier.indexOf(",") + 1).trim(); _qualifier = _qualifier.substring(0, _qualifier.indexOf(",")).trim(); } qualifier = Integer.parseInt(_qualifier); // TODO: handle parse error signGPG = new Boolean(_signGPG); this.log.info("Step number is " + qualifier); try { for (MavenProject p : this.reactorProjects) { if (qualifier == 2) { for (String profile : profiles) { session.getSettings().addActiveProfile(profile); } p.getModel().getProperties().put("ecosystemVersion", p.getVersion()); } propertiesManager = CommonMojo.propertiesManager(session, p); if (doReplace(p.getFile(), RegexpUtil.asOptions(""))) { if (signGPG) { signGPG(p); } } } } catch (Throwable t) { throw new MojoFailureException("Could not perform replacement in POMs.", t); } finally { deleteTempSettings(); } }
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
private void signGPG(MavenProject p) throws MojoExecutionException, MavenInvocationException, MojoFailureException, IOException { InvocationRequest request = getInvocationRequest(p); Invoker invoker = getInvoker(); InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { CommandLineException executionException = result.getExecutionException(); if (executionException != null) { throw new MojoFailureException("Error during project build: " + executionException.getMessage(), executionException); } else {//from w w w. j a v a2 s . c o m throw new MojoFailureException("Error during project build: " + result.getExitCode()); } } if (!p.isExecutionRoot() || p.getModel().getModules().isEmpty()) { File gpgTempDirectory = null; try { URL gpgTempDirectoryURL = new URL(request.getProperties().get("url").toString()); gpgTempDirectory = new File(gpgTempDirectoryURL.getFile()); File pomGpgSignature = new File(gpgTempDirectory, p.getGroupId().replaceAll("\\.", "/") + "/" + p.getArtifactId() + "/" + p.getVersion() + "/" + p.getArtifactId() + "-" + p.getVersion() + ".pom.asc"); File gpgSignatureDest = new File(p.getBuild().getDirectory(), pomGpgSignature.getName()); pomGpgSignature = new File(p.getFile().getParentFile(), "pom.xml.asc"); org.apache.commons.io.FileUtils.copyFile(pomGpgSignature, gpgSignatureDest); } finally { if (gpgTempDirectory != null && gpgTempDirectory.exists()) { org.apache.commons.io.FileUtils.deleteDirectory(gpgTempDirectory); } File ascFile = new File(p.getFile().getParentFile(), "pom.xml.asc"); if (ascFile.exists()) { ascFile.delete(); } } } }
From source file:io.teecube.t3.GenericReplacerMojo.java
License:Apache License
private InvocationRequest getInvocationRequest(MavenProject p) throws MojoExecutionException, IOException { InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(p.getFile());/*w w w.j a v a 2 s .c om*/ if (p.isExecutionRoot() && !p.getModel().getModules().isEmpty()) { request.setGoals(Lists.newArrayList("gpg:sign")); } else { File gpgDirectory = Files.createTempDir(); request.setGoals(Lists.newArrayList("gpg:sign-and-deploy-file")); Properties properties = new Properties(); properties.put("file", p.getFile().getAbsolutePath()); // properties.put("pomFile", p.getFile().getAbsolutePath()); properties.put("groupId", p.getGroupId()); properties.put("artifactId", p.getArtifactId()); properties.put("version", p.getVersion()); properties.put("repositoryId", "null"); properties.put("url", gpgDirectory.toURI().toURL().toString()); request.setProperties(properties); } request.setRecursive(false); this.tempSettingsFile = createAndSetTempSettings(request); return request; }
From source file:it.session.maven.plugin.TilesMavenLifecycleParticipant.java
License:Apache License
protected void mergeTile(MavenProject currentProject, String propertyName, RepositorySystemSession repositorySystemSession) throws MavenExecutionException { String propertyValue = currentProject.getProperties().getProperty(propertyName); StringTokenizer propertyTokens = new StringTokenizer(propertyValue, ":"); String groupId = propertyTokens.nextToken(); String artifactId = propertyTokens.nextToken(); String version = propertyTokens.nextToken(); String currentTileInformation = String.format("'%s:%s:%s'", groupId, artifactId, version); try {/* w w w . j a v a2 s . c o m*/ File artifactFile = this.resolveArtifact(currentProject, groupId, artifactId, version, repositorySystemSession); Model tileModel = this.reader.read(new FileInputStream(artifactFile)); this.modelMerger.merge(currentProject.getModel(), tileModel, false, null); //If invoked by tests, logger is null //@TODO properly inject logger on TilesMavenLifecycleParticipantTest.java if (logger != null) { logger.info(String.format("Loaded Maven Tile " + currentTileInformation)); } } catch (FileNotFoundException e) { throw new MavenExecutionException("Error loading tiles " + currentTileInformation, e); } catch (XmlPullParserException e) { throw new MavenExecutionException("Error building tiles " + currentTileInformation, e); } catch (IOException e) { throw new MavenExecutionException("Error parsing tiles " + currentTileInformation, e); } catch (MojoExecutionException e) { throw new MavenExecutionException("Error retrieving tiles " + currentTileInformation, e); } }
From source file:kr.motd.maven.os.DetectExtension.java
License:Apache License
private void interpolate(Map<String, String> dict, MavenProject p) { if (p == null) { return;//ww w. ja v a 2s . c o m } interpolate(dict, p.getParent()); interpolate(dict, p.getModel()); for (ModelBase model : p.getActiveProfiles()) { interpolate(dict, model); } }
From source file:licenseUtil.LicenseUtil.java
License:Apache License
public static void main(String[] args) throws IOException, IncompleteLicenseObjectException { if (args.length == 0) { logger.error("Missing parameters. Use --help to get a list of the possible options."); } else if (args[0].equals("--addPomToTsv")) { if (args.length < 4) logger.error(//from ww w . j a va 2 s . c o m "Missing arguments for option --addPomToTsv. Please specify <pomFileName> <licenses.stub.tsv> <currentVersion> or use the option --help for further information."); String pomFN = args[1]; String spreadSheetFN = args[2]; String currentVersion = args[3]; MavenProject project = null; try { project = Utils.readPom(new File(pomFN)); } catch (XmlPullParserException e) { logger.error("Could not parse pom file: \"" + pomFN + "\""); } LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addMavenProject(project, currentVersion); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--writeLicense3rdParty")) { if (args.length < 4) logger.error( "Missing arguments for option --writeLicense3rdParty. Please provide <licenses.enhanced.tsv> <processModule> <currentVersion> [and <targetDir>] or use the option --help for further information."); String spreadSheetFN = args[1]; String processModule = args[2]; String currentVersion = args[3]; HashMap<String, String> targetDirs = new HashMap<>(); if (args.length > 4) { File targetDir = new File(args[4]); logger.info("scan pom files in direct subdirectories of \"" + targetDir.getPath() + "\" to obtain target locations for 3rd party license files..."); File[] subdirs = targetDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); for (File subdir : subdirs) { File pomFile = new File(subdir.getPath() + File.separator + POM_FN); if (!pomFile.exists()) continue; MavenProject mavenProject; try { mavenProject = Utils.readPom(pomFile); } catch (Exception e) { logger.warn("Could not read from pom file: \"" + pomFile.getPath() + "\" because of " + e.getMessage()); continue; } targetDirs.put(mavenProject.getModel().getArtifactId(), subdir.getAbsolutePath()); } } LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetFN); if (processModule.toUpperCase().equals("ALL")) { for (String module : licensingList.getNonFixedHeaders()) { try { writeLicense3rdPartyFile(module, licensingList, currentVersion, targetDirs.get(module)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + module + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else { try { writeLicense3rdPartyFile(processModule, licensingList, currentVersion, targetDirs.get(processModule)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + processModule + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else if (args[0].equals("--buildEffectivePom")) { Utils.writeEffectivePom(new File(args[1]), (new File(EFFECTIVE_POM_FN)).getAbsolutePath()); } else if (args[0].equals("--updateTsvWithProjectsInFolder")) { if (args.length < 4) logger.error( "Missing arguments for option --processProjectsInFolder. Please provide <superDirectory> <licenses.stub.tsv> and <currentVersion> or use the option --help for further information."); File directory = new File(args[1]); String spreadSheetFN = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addAll(processProjectsInFolder(directory, currentVersion, false)); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--purgeTsv")) { if (args.length < 3) logger.error( "Missing arguments for option --purgeTsv. Please provide <spreadSheetIN.tsv>, <spreadSheetOUT.tsv> and <currentVersion> or use the option --help for further information."); String spreadSheetIN = args[1]; String spreadSheetOUT = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetIN); licensingList.purge(currentVersion); licensingList.writeToSpreadsheet(spreadSheetOUT); } else if (args[0].equals("--help")) { InputStream in = LicenseUtil.class.getClassLoader().getResourceAsStream(README_PATH); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } else { logger.error("Unknown parameter: " + args[0] + ". Use --help to get a list of the possible options."); } }
From source file:licenseUtil.Utils.java
License:Apache License
public static MavenProject resolveArtifact(MavenProject project, Artifact artifact) throws ArtifactResolutionException, IOException, XmlPullParserException { logger.debug("resolve artifact " + artifact.toString()); RepositorySystem system = Booter.newRepositorySystem(); RepositorySystemSession session = Booter.newRepositorySystemSession(system); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); List<RemoteRepository> remotes = new LinkedList<>(); for (org.apache.maven.model.Repository repository : project.getModel().getRepositories()) { remotes.add(new RemoteRepository.Builder(repository.getId(), "default", repository.getUrl()).build()); }/*from w w w. ja va2s . c o m*/ remotes.add(Booter.newCentralRepository()); artifactRequest.setRepositories(remotes); ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest); artifact = artifactResult.getArtifact(); logger.info("resolved artifact \"" + artifact + "\" to \"" + artifact.getFile() + "\""); return Utils.readPom(artifact.getFile()); }
From source file:npanday.plugin.MavenProjectConfigurationAppender.java
License:Apache License
private String ToString(MavenProject mavenProject) { StringWriter stringWriter = new StringWriter(); try {//from w w w . j a v a 2 s . co m new MavenXpp3Writer().write(stringWriter, mavenProject.getModel()); } catch (IOException e) { e.printStackTrace(); } finally { IOUtil.close(stringWriter); } return stringWriter.getBuffer().toString().replaceFirst("<project>", "<project xmlns=\"http://maven.apache.org/POM/4.0.0\">"); }
From source file:org.andromda.maven.plugin.bootstrap.install.BootstrapInstallMojo.java
/** * Clears the POM's model of its parent or any dependencies * it may have so that we can write a POM that isn't dependent on anything * (which we need for bootstrap artifacts). * * @param bootstrapPomFile the bootstrap POM file to write. *///from w w w .ja v a2 s. co m private void writeMinimalPom(final File bootstrapPomFile) throws IOException { final Model model = this.project.getModel(); final MavenProject minimalProject = new MavenProject(); final Model minModel = minimalProject.getModel(); minModel.setGroupId(getBootstrapGroupId(this.project.getArtifact())); minModel.setArtifactId(model.getArtifactId()); minModel.setVersion(model.getVersion()); minModel.setName(model.getName()); minModel.setPackaging("jar"); minModel.setDescription(model.getDescription()); minModel.setModelEncoding(model.getModelEncoding()); minModel.setModelVersion(model.getModelVersion()); minModel.setUrl(model.getUrl()); minModel.setScm(model.getScm()); minModel.setDevelopers(model.getDevelopers()); minModel.setCiManagement(model.getCiManagement()); minModel.setIssueManagement(model.getIssueManagement()); minModel.setPrerequisites(model.getPrerequisites()); minModel.setOrganization(model.getOrganization()); minModel.setInceptionYear(model.getInceptionYear()); minModel.setLicenses(model.getLicenses()); final List<Dependency> dependencies = new ArrayList<Dependency>(model.getDependencies()); // filter all of andromda dependencies away CollectionUtils.filter(dependencies, new Predicate() { public boolean evaluate(Object object) { Dependency dependency = (Dependency) object; final String lGroupId = dependency.getGroupId(); return !lGroupId.startsWith("org.andromda") || lGroupId.startsWith("org.andromda.thirdparty"); } }); minModel.setDependencies(dependencies); final FileWriter fileWriter = new FileWriter(bootstrapPomFile); minimalProject.writeModel(fileWriter); fileWriter.flush(); }
From source file:org.apache.felix.bundleplugin.BundlePlugin.java
License:Apache License
protected Properties getDefaultProperties(MavenProject currentProject) { Properties properties = new Properties(); String bsn;/*from w w w . java 2 s.com*/ try { bsn = getMaven2OsgiConverter().getBundleSymbolicName(currentProject.getArtifact()); } catch (Exception e) { bsn = currentProject.getGroupId() + "." + currentProject.getArtifactId(); } // Setup defaults properties.put(MAVEN_SYMBOLICNAME, bsn); properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn); properties.put(Analyzer.IMPORT_PACKAGE, "*"); properties.put(Analyzer.BUNDLE_VERSION, getMaven2OsgiConverter().getVersion(currentProject.getVersion())); // remove the extraneous Include-Resource and Private-Package entries from generated manifest properties.put(Analyzer.REMOVE_HEADERS, Analyzer.INCLUDE_RESOURCE + ',' + Analyzer.PRIVATE_PACKAGE); header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription()); StringBuffer licenseText = printLicenses(currentProject.getLicenses()); if (licenseText != null) { header(properties, Analyzer.BUNDLE_LICENSE, licenseText); } header(properties, Analyzer.BUNDLE_NAME, currentProject.getName()); if (currentProject.getOrganization() != null) { String organizationName = currentProject.getOrganization().getName(); header(properties, Analyzer.BUNDLE_VENDOR, organizationName); properties.put("project.organization.name", organizationName); properties.put("pom.organization.name", organizationName); if (currentProject.getOrganization().getUrl() != null) { String organizationUrl = currentProject.getOrganization().getUrl(); header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl); properties.put("project.organization.url", organizationUrl); properties.put("pom.organization.url", organizationUrl); } } properties.putAll(currentProject.getProperties()); properties.putAll(currentProject.getModel().getProperties()); properties.putAll(getProperties(currentProject.getModel(), "project.build.")); properties.putAll(getProperties(currentProject.getModel(), "pom.")); properties.putAll(getProperties(currentProject.getModel(), "project.")); properties.put("project.baseDir", baseDir); properties.put("project.build.directory", getBuildDirectory()); properties.put("project.build.outputdirectory", getOutputDirectory()); properties.put("classifier", classifier == null ? "" : classifier); // Add default plugins header(properties, Analyzer.PLUGIN, BlueprintPlugin.class.getName() + "," + SpringXMLType.class.getName()); return properties; }