List of usage examples for org.apache.maven.project MavenProject MavenProject
public MavenProject(MavenProject project)
From source file:org.apifocal.maven.plugins.bom.AbstractBomMojo.java
License:Apache License
/** * Read a file as a {@link MavenProject}. * * @see/*w ww.j a v a2 s .c om*/ * http://stackoverflow.com/questions/951643/collapsing-parent-pom-into-the-child/1001575#1001575 */ public static MavenProject readBareProject(final File file) throws IOException { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = null; try { model = reader.read(new FileReader(file)); } catch (IOException | XmlPullParserException ex) { throw new IOException("Cannot parse BOM artifact", ex); } return new MavenProject(model); }
From source file:org.artificer.integration.java.artifactbuilder.MavenPomArtifactBuilder.java
License:Apache License
@Override public ArtifactBuilder buildArtifacts(BaseArtifactType primaryArtifact, ArtifactContent artifactContent) throws Exception { super.buildArtifacts(primaryArtifact, artifactContent); try {// w w w . j a va2 s . c o m Model model = new MavenXpp3Reader().read(getContentStream()); MavenProject project = new MavenProject(model); ((ExtendedDocument) primaryArtifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (primaryArtifact.getDescription() == null) primaryArtifact.setDescription(project.getDescription()); if (primaryArtifact.getName() == null) primaryArtifact.setName(project.getName()); if (primaryArtifact.getVersion() == null) primaryArtifact.setVersion(project.getVersion()); //set the GAV and packaging info ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } return this; } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.bigtester.ate.experimentals.DynamicClassLoader.java
License:Apache License
@Test public void test3() throws FileNotFoundException, IOException, XmlPullParserException, DependencyResolutionRequiredException { MavenXpp3Reader reader = new MavenXpp3Reader(); File pomFile = new File("pom.xml"); Model model = reader.read(new FileReader(pomFile)); MavenProject project = new MavenProject(model); // Collection<File> jars = new Classpath( // project, // new File("/home/peidong/.m2/respository"), // "test" // the scope you're interested in // ); List<Dependency> runtimeClasspathElements = project.getDependencies(); for (Dependency runtimeClasspathElement : runtimeClasspathElements) { System.out.println(runtimeClasspathElement); }//from w w w . java 2 s .co m // System.out.println("--------- Model -------------"); // for (Dependency dependency : modelPom.getDependencies()) { // System.out.println("Model Dependency:" + dependency); // } }
From source file:org.codehaus.cargo.documentation.ConfluenceContainerDocumentationGenerator.java
License:Apache License
/** * Returns the download URL used for testing the given container. * @param containerId Container ID.// w w w . j a va 2 s . c om * @return Download URL for testing <code>containerId</code>, <code>null</code> if no download * URL is set. */ public String getContainerServerDownloadUrl(String containerId) { File pom = new File(SAMPLES_DIRECTORY, POM).getAbsoluteFile(); Model model = new Model(); try { model = POM_READER.read(new FileReader(pom)); } catch (Exception e) { throw new IllegalStateException("Caught Exception reading pom.xml", e); } MavenProject project = new MavenProject(model); project.setFile(pom); Map<String, Plugin> plugins = project.getPluginManagement().getPluginsAsMap(); Plugin surefire = plugins.get(SUREFIRE_PLUGIN); if (surefire == null) { throw new IllegalStateException("Cannot find plugin " + SUREFIRE_PLUGIN + " in pom file " + pom + ". Found plugins: " + plugins.keySet()); } Xpp3Dom configuration = (Xpp3Dom) surefire.getConfiguration(); if (configuration == null) { throw new IllegalStateException( "Plugin " + SUREFIRE_PLUGIN + " in pom file " + pom + " does not have any configuration."); } Xpp3Dom systemProperties = configuration.getChild(SYSTEM_PROPERTIES); if (systemProperties == null) { throw new IllegalStateException("Plugin " + SUREFIRE_PLUGIN + " in pom file " + pom + " does not have any " + SYSTEM_PROPERTIES + " in its configuration."); } String urlName = "cargo." + containerId + ".url"; for (Xpp3Dom property : systemProperties.getChildren()) { Xpp3Dom nameChild = property.getChild("name"); Xpp3Dom valueChild = property.getChild("value"); if (nameChild == null || valueChild == null) { throw new IllegalStateException("One of the " + SUREFIRE_PLUGIN + "'s configuration options in pom file " + pom + " is incomplete:\n" + property); } if (urlName.equals(nameChild.getValue())) { return valueChild.getValue(); } } return null; }
From source file:org.codehaus.cargo.documentation.ConfluenceProjectStructureDocumentationGenerator.java
License:Apache License
/** * Creates a MavenProject from a given POM.XML file. * @param pom the POM.XML file to create a MavenProject from. * @return a MavenProject represented by the given POM.XML file. *///from w w w.j a va2 s.c o m private MavenProject createProjectFromPom(File pom) { Model model = new Model(); try { model = POM_READER.read(new FileReader(pom)); } catch (Exception e) { throw new IllegalStateException("Caught Exception reading pom.xml", e); } MavenProject project = new MavenProject(model); project.setFile(pom); return project; }
From source file:org.codehaus.cargo.maven2.DependencyCalculator.java
License:Apache License
/** * Fixup the project artifact./*w w w .j a v a 2s . co m*/ * @throws Exception If anything goes wrong. */ protected void fixupProjectArtifact() throws Exception { MavenProject mp2 = new MavenProject(mavenProject); // For each of our dependencies.. for (Object artifact : mp2.createArtifacts(artifactFactory, null, null)) { Artifact art = (Artifact) artifact; if (art.getType().equals("war")) { // Sigh... Artifact art2 = artifactFactory.createArtifactWithClassifier(art.getGroupId(), art.getArtifactId(), art.getVersion(), "pom", null); fixupRepositoryArtifact(art2); } } // If we mess with this model, it's the 'REAL' model. So lets copy it Model pomFile = mp2.getModel(); File outFile = File.createTempFile("pom", ".xml"); MavenXpp3Writer pomWriter = new MavenXpp3Writer(); pomWriter.write(new FileWriter(outFile), pomFile); MavenXpp3Reader pomReader = new MavenXpp3Reader(); pomFile = pomReader.read(new FileReader(outFile)); Artifact art = mp2.getArtifact(); fixModelAndSaveInRepository(art, pomFile); outFile.delete(); }
From source file:org.eiichiro.gig.shell.Main.java
License:Open Source License
/** * @param args/*from ww w. ja v a 2 s. c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { Shell shell = new Shell(); shell.register(new Quit(shell)); shell.register(new Exit(shell)); shell.register(new Help(shell)); shell.register(new Hint(shell)); Console console = shell.console(); console.println(Colors.blue(" ____ _")); console.println(Colors.blue(" / ___(_) __ _")); console.println(Colors.blue("| | _| |/ _` |")); console.println(Colors.blue("| |_| | | (_| |")); console.println(Colors.blue(" \\____|_|\\__, |")); console.println(Colors.blue(" |___/")); console.println(""); console.println(Colors.blue("Gig Shell " + Version.MAJOR + "." + Version.MINER + "." + Version.BUILD + " (Experimental Beta) http://gig.eiichiro.org/")); console.println(""); console.println(Colors.blue("Welcome to Gig. Hit the TAB or press 'hint' to display available commands.")); console.println(Colors.blue("Press 'help command' to display the detailed information for the command.")); console.println(Colors.blue("Press 'quit' or 'exit' to exit this session. Enjoy!")); console.println(""); String dir = Environment.getProperty("user.dir"); File pom = new File(dir + File.separator + "pom.xml"); String prompt = "gig"; if (pom.exists()) { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(pom)); MavenProject project = new MavenProject(model); String artifactId = project.getArtifactId(); String version = project.getVersion(); prompt = prompt + Colors.yellow(":[" + artifactId + "-" + version + "]"); File gig = new File(dir + File.pathSeparator + ".gig"); if (!gig.exists()) { gig.mkdir(); } shell.register(new Scan(shell)); } console.prompt(prompt + "> "); shell.start(); }
From source file:org.gradle.api.internal.artifacts.publish.maven.DefaultMavenPom.java
License:Apache License
public DefaultMavenPom setModel(Model model) { this.mavenProject = new MavenProject(model); return this; }
From source file:org.gradle.api.publication.maven.internal.DefaultMavenPom.java
License:Apache License
public DefaultMavenPom setModel(Object model) { this.mavenProject = new MavenProject((Model) model); return this; }
From source file:org.gradle.api.publication.maven.internal.pom.DefaultMavenPom.java
License:Apache License
public MavenProject getMavenProject() { return new MavenProject(model); }