Java 类org.apache.maven.model.Parent 实例源码

项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void writeParent(Parent parent, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if (parent.getGroupId() != null) {
        writeValue(serializer, "groupId", parent.getGroupId(), parent);
    }
    if (parent.getArtifactId() != null) {
        writeValue(serializer, "artifactId", parent.getArtifactId(), parent);
    }
    if (parent.getVersion() != null) {
        writeValue(serializer, "version", parent.getVersion(), parent);
    }
    if ((parent.getRelativePath() != null) && !parent.getRelativePath().equals("../pom.xml")) {
        writeValue(serializer, "relativePath", parent.getRelativePath(), parent);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(parent, "", start, b.length());
}
项目:fabric8-forge    文件:SetupProjectHelper.java   
@Deprecated
public static boolean isFunktionParentPom(Project project) {
    MavenFacet mavenFacet = project.getFacet(MavenFacet.class);
    if (mavenFacet != null) {
        Model model = mavenFacet.getModel();
        if (model != null) {
            Parent parent = model.getParent();
            if (parent != null) {
                String groupId = parent.getGroupId();
                if (groupId != null && groupId.startsWith("io.fabric8.funktion")) {
                    return true;
                }
            }
        }
    }
    return false;
}
项目:gradle-maven-share    文件:PomResolver.java   
protected ResolvedPom resolveParent(Model model, File pomFile, PomResolveCache cache, PomSource pomSource) throws Exception {
    Parent rawParent = model.getParent();
    if (rawParent != null) {
        if (rawParent.getGroupId() == null || rawParent.getArtifactId() == null || rawParent.getVersion() == null) {
            throw new RuntimeException("Invalid parent for artifact " + createGav(model));
        }
        ResolvedPom parent = cache.getResolvedPom(rawParent.getGroupId(), rawParent.getArtifactId(), rawParent.getVersion());
        if (parent == null) {
            if (pomFile != null && rawParent.getRelativePath() != null) {
                File parentPomFile = new File(pomFile.getParentFile(), rawParent.getRelativePath());
                if (!parentPomFile.isFile()) {
                    parentPomFile = new File(parentPomFile, "pom.xml");
                }
                parent = resolvePom(parentPomFile, cache, pomSource);
            } else {
                try (
                    InputStream parentIn = pomSource.getPom(rawParent.getGroupId(), rawParent.getArtifactId(), rawParent.getVersion());
                ) {
                    parent = resolvePom(parentIn, null, cache, pomSource);
                }
            }
        }
        return parent;
    }
    return null;
}
项目:meghanada-server    文件:POMParser.java   
@Override
public ModelSource2 resolveModel(final Parent parent) throws UnresolvableModelException {
  final String groupId = parent.getGroupId();
  final String artifactId = parent.getArtifactId();
  final String version = parent.getVersion();
  final ModelSource2 model = resolveModel(groupId, artifactId, version);
  if (nonNull(model)) {
    return model;
  }
  String relativePath = parent.getRelativePath();

  if (nonNull(relativePath) && !relativePath.isEmpty()) {
    File pom = new File(this.projectRoot, relativePath);
    if (!relativePath.endsWith("pom.xml")) {
      pom = new File(relativePath, "pom.xml");
    }
    if (!loaded.contains(pom)) {
      loaded.add(pom);
    }
    if (pom.exists()) {
      return new FileModelSource(pom);
    }
  }
  return null;
}
项目:hybris-maven-plugin    文件:CreatePomFromExtensionTask.java   
private Model createModel(TaskContext taskContext, final Extension extension) {
    final Model model = new Model();
    model.setModelVersion(MODEL_VERSION);
    model.setArtifactId(extension.getName());
    model.setVersion(taskContext.getHybrisVersion().getVersion());
    final Parent parent = new Parent();
    parent.setGroupId(HYBRIS__GROUP_ID);
    parent.setArtifactId(PLATFORM__ARTIFACT_ID);
    parent.setVersion(taskContext.getHybrisVersion().getVersion());
    model.setParent(parent);
    setExtensionPackaging(taskContext, model);
    addExtensionDependencies(taskContext, extension, model);
    addImplicitDependencies(taskContext, extension, model);
    addExternalDependencies(taskContext, extension, model);
    // resolveDependencyVersionConflicts(taskContext, extension, model);
    return model;
}
项目:unleash-maven-plugin    文件:SetReleaseVersions.java   
private void setParentVersion(MavenProject project, Document document) {
  Parent parent = project.getModel().getParent();
  if (parent != null) {
    Map<ReleasePhase, ArtifactCoordinates> coordinatesByPhase = this.metadata
        .getArtifactCoordinatesByPhase(parent.getGroupId(), parent.getArtifactId());
    ArtifactCoordinates oldCoordinates = coordinatesByPhase.get(ReleasePhase.PRE_RELEASE);
    ArtifactCoordinates newCoordinates = coordinatesByPhase.get(ReleasePhase.RELEASE);

    // null indicates that the parent is not part of the reactor projects since no release version had been calculated
    // for it
    if (newCoordinates != null) {
      this.log.debug("\tUpdate of parent version of module '" + project.getGroupId() + ":" + project.getArtifact()
          + "' [" + oldCoordinates.getVersion() + " => " + newCoordinates.getVersion() + "]");
      PomUtil.setParentVersion(project.getModel(), document, newCoordinates.getVersion());
    }
  }
}
项目:unleash-maven-plugin    文件:SetNextDevVersion.java   
private void setParentVersion(MavenProject project, Document document) {
  Parent parent = project.getModel().getParent();
  if (parent != null) {
    Map<ReleasePhase, ArtifactCoordinates> coordinatesByPhase = this.metadata
        .getArtifactCoordinatesByPhase(parent.getGroupId(), parent.getArtifactId());
    ArtifactCoordinates oldCoordinates = coordinatesByPhase.get(ReleasePhase.RELEASE);
    ArtifactCoordinates newCoordinates = coordinatesByPhase.get(ReleasePhase.POST_RELEASE);

    // null indicates that the parent is not part of the reactor projects since no release version had been calculated
    // for it
    if (newCoordinates != null) {
      this.log.debug("\t\tUpdate of parent version of module '" + project.getGroupId() + ":" + project.getArtifact()
          + "' [" + oldCoordinates.getVersion() + " => " + newCoordinates.getVersion() + "]");
      PomUtil.setParentVersion(project.getModel(), document, newCoordinates.getVersion());
    }
  }
}
项目:unleash-maven-plugin    文件:PomUtil.java   
/**
 * Changes the project's parent version of the POM as well as directly in the XML document preserving the whole
 * document formatting.
 *
 * @param model the POM where to adapt the project's parent version.
 * @param document the POM as an XML document in which the project's parent version shall be adapted.
 * @param newParentVersion the new version to set for the project parent.
 */
public static void setParentVersion(Model model, Document document, String newParentVersion) {
  Preconditions.checkArgument(hasChildNode(document, NODE_NAME_PROJECT),
      "The document doesn't seem to be a POM model, project element is missing.");

  // first step: update parent version of the in-memory model
  Parent parent = model.getParent();
  if (parent != null) {
    parent.setVersion(newParentVersion);
  }

  // second step: update the parent version in the DOM document that will be serialized for later building
  Node parentNode = document.getDocumentElement().getElementsByTagName(PomUtil.NODE_NAME_PARENT).item(0);
  if (parentNode != null) {
    NodeList children = parentNode.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (Objects.equal(child.getNodeName(), PomUtil.NODE_NAME_VERSION)) {
        child.setTextContent(newParentVersion);
      }
    }
  }
}
项目:versions-maven-plugin    文件:PomHelper.java   
/**
 * Returns all the models that have a specified groupId and artifactId as parent.
 *
 * @param reactor The map of models keyed by path.
 * @param groupId The groupId of the parent.
 * @param artifactId The artifactId of the parent.
 * @return a map of models that have a specified groupId and artifactId as parent keyed by path.
 */
public static Map<String, Model> getChildModels( Map<String, Model> reactor, String groupId, String artifactId )
{
    final Map<String, Model> result = new LinkedHashMap<String, Model>();
    for ( Map.Entry<String, Model> entry : reactor.entrySet() )
    {
        final String path = entry.getKey();
        final Model model = entry.getValue();
        final Parent parent = model.getParent();
        if ( parent != null && groupId.equals( parent.getGroupId() )
            && artifactId.equals( parent.getArtifactId() ) )
        {
            result.put( path, model );
        }
    }
    return result;
}
项目:mvn2nix-maven-plugin    文件:ParentPOMPropagatingArtifactDescriptorReaderDelegate.java   
@Override
public void populateResult(RepositorySystemSession session,
    ArtifactDescriptorResult result,
    Model model) {
    super.populateResult(session, result, model);
    Parent parent = model.getParent();
    if (parent != null) {
        DefaultArtifact art =
            new DefaultArtifact(parent.getGroupId(),
                parent.getArtifactId(),
                "pom",
                parent.getVersion());
        Dependency dep = new Dependency(art, "compile");
        result.addDependency(dep);
    }
}
项目:msf4j    文件:MSF4JProjectImporter.java   
private void saveMavenParentInfo(MavenProjectInfo projectInfo) throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = projectInfo.getPomFile();// project.getFile(POM_FILE).getLocation().toFile();
    MavenProject mavenProject = null;
    mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    Parent msf4jParent = new Parent();
    msf4jParent.setGroupId(MSF4J_SERVICE_PARENT_GROUP_ID);
    msf4jParent.setArtifactId(MSF4J_SERVICE_PARENT_ARTIFACT_ID);
    msf4jParent.setVersion(MSF4JArtifactConstants.getMSF4JServiceParentVersion());
    mavenProject.getModel().setParent(msf4jParent);

    Properties generatedProperties = mavenProject.getModel().getProperties();
    generatedProperties.clear();

    mavenProject.getModel().addProperty(MSF4J_MAIN_CLASS_PROPERTY, DEFAULT_MAIN_CLASS_PROPERTY_VALUE);
    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}
项目:artifactory    文件:MavenModelUtils.java   
public static MavenArtifactInfo mavenModelToArtifactInfo(Model model) {
    Parent parent = model.getParent();
    String groupId = model.getGroupId();
    if (groupId == null && parent != null) {
        groupId = parent.getGroupId();
    }
    MavenArtifactInfo artifactInfo = new MavenArtifactInfo();
    artifactInfo.setGroupId(groupId);
    artifactInfo.setArtifactId(model.getArtifactId());
    String version = model.getVersion();
    if (version == null && parent != null) {
        version = parent.getVersion();
    }
    artifactInfo.setVersion(version);
    return artifactInfo;
}
项目:motech    文件:PomInformationTest.java   
@Test
public void shouldParseParentPomFile() throws IOException {
    Properties properties = new Properties();
    properties.put("test.properties", "testParent");
    // Because we use <version> and <artifactId> tags in our tested pom, the parsing method should add this as properties
    properties.put("project.version", "0-27-SNAPSHOT");
    properties.put("project.artifactId", "motech-platform-server-api");

    try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("pom/parentPom.xml")) {
        pomInformation = new PomInformation();
        pomInformation.parseParentPom(inputStream);
    }

    PomInformation parentPom = pomInformation.getParentPomInformation();
    assertEquals(properties, parentPom.getProperties());

    Parent parentFromParsing = parentPom.getParent();
    assertEquals("0.27-SNAPSHOT", parentFromParsing.getVersion());
    assertEquals("motech", parentFromParsing.getArtifactId());
    assertEquals("org.motechproject", parentFromParsing.getGroupId());
}
项目:versions-maven-plugin-svn-clone    文件:PomHelper.java   
/**
 * Returns all the models that have a specified groupId and artifactId as parent.
 *
 * @param reactor    The map of models keyed by path.
 * @param groupId    The groupId of the parent.
 * @param artifactId The artifactId of the parent.
 * @return a map of models that have a specified groupId and artifactId as parent keyed by path.
 */
public static Map<String, Model> getChildModels( Map<String, Model> reactor, String groupId, String artifactId )
{
    final Map<String, Model> result = new LinkedHashMap<String, Model>();
    for ( Map.Entry<String, Model> entry : reactor.entrySet() )
    {
        final String path = entry.getKey();
        final Model model = entry.getValue();
        final Parent parent = model.getParent();
        if ( parent != null && groupId.equals( parent.getGroupId() ) &&
            artifactId.equals( parent.getArtifactId() ) )
        {
            result.put( path, model );
        }
    }
    return result;
}
项目:developer-studio    文件:MavenDetailsPage.java   
private void setParentMavenInfo(Parent info) {
    if (info != null) {
        setParentProjectName(info.getArtifactId());
        setParentGroupID(info.getGroupId());
        setParentArtifactID(info.getArtifactId());
        setParentVersion(info.getVersion());
        setParentRelativePath(info.getRelativePath());
        txtParentArtifactId.setText(getParentArtifactID());
        txtParentGroupId.setText(getParentGroupID());
        txtParentVersion.setText(getParentVersion());
        String parentRelativePath2 = getParentRelativePath();
        if (hasParentProject && parentRelativePath2 != null) {
            txtRelativePath.setText(parentRelativePath2);
        } else {
            txtRelativePath.setText("");
        }
    }

}
项目:srclib-java    文件:Resolver.java   
/**
 * This method tries to retrieve SCM URL, if POM model for given dependency does not specify SCM URL and
 * parent model belongs to the same group, we'll try to fecth URL from the parent model
 * @param dependency dependency to retrieve SCM URL for
 * @return SCM URL or null
 * @throws IOException
 * @throws XmlPullParserException
 */
private static String getScmUrl(RawDependency dependency) throws IOException, XmlPullParserException {
    Model model = fetchModel(dependency);
    while (model != null) {
        Scm scm = model.getScm();
        if (scm != null) {
            return scm.getUrl();
        }

        Parent parent = model.getParent();
        if (parent == null) {
            return null;
        }
        if (!StringUtils.equals(parent.getGroupId(), dependency.groupID)) {
            return null;
        }
        dependency = new RawDependency(parent.getGroupId(),
                parent.getArtifactId(),
                parent.getVersion(), null, null);
        model = fetchModel(dependency);
    }
    return null;
}
项目:aem-eclipse-developer-tools    文件:NewGraniteProjectWizard.java   
private void fixParentProject(IProject p, IProject parentProject)
        throws CoreException {
    IFile existingPom = p.getFile("pom.xml");
    Model model = MavenPlugin.getMavenModelManager().readMavenModel(existingPom);
    Model parent = MavenPlugin.getMavenModelManager().readMavenModel(parentProject.getFile("pom.xml"));
    //Parent oldParent = model.getParent();
    Parent newParent = new Parent();
    newParent.setGroupId(parent.getGroupId());
    newParent.setArtifactId(parent.getArtifactId());
    newParent.setRelativePath(calculateRelativePath(p, parentProject));
    newParent.setVersion(parent.getVersion());
    model.setParent(newParent);
    // outright deletion doesn't work on windows as the process has a ref to the file itself
    // so creating a temp '_newpom_.xml'
    final IFile newPom = p.getFile("_newpom_.xml");
    MavenPlugin.getMavenModelManager().createMavenModel(newPom, model);
    // then copying that content over to the pom.xml
    existingPom.setContents(newPom.getContents(), true,  true, new NullProgressMonitor());
    // and deleting the temp pom
    newPom.delete(true,  false, new NullProgressMonitor());

}
项目:griffon-forge-addon    文件:AbstractGriffonFacet.java   
protected void addDependencies() {
    Parent p = new Parent();
    p.setGroupId(GRIFFON_GROUP_ID);
    p.setArtifactId(GRIFFON_MASTERPOM_ARTIFACT_ID);
    p.setVersion("1.0.0");
    MavenFacet mavenFacet = getFaceted().getFacet(MavenFacet.class);
    Model model = mavenFacet.getModel();
    model.setParent(p);
    mavenFacet.setModel(model);

    DependencyFacet  facet = getFaceted().getFacet(DependencyFacet.class);
    facet.addRepository("jcenter","http://jcenter.bintray.com");
    facet.addRepository("griffon-plugins","http://dl.bintray.com/griffon/griffon-plugins");

    MetadataFacet mdfacet = getFaceted().getFacet(MetadataFacet.class);
    mdfacet.setDirectProperty("griffon.version","2.2.0");
    mdfacet.setDirectProperty("application.main.class",mdfacet.getProjectGroupName()+".Launcher");
    mdfacet.setDirectProperty("maven.compiler.source","1.8");
    mdfacet.setDirectProperty("maven.compiler.target","1.8");

    builder = DependencyBuilder.create();
    addDependency(LOG4J);
    addDependency(SLF4J_LOG4J12);
    addDependency(SPOCK_CORE);
    addDependency(JUNIT);
}
项目:oceano    文件:MavenProjectTest.java   
public void testIdentityProtoInheritance()
{
    Parent parent = new Parent();

    parent.setGroupId( "test-group" );
    parent.setVersion( "1000" );
    parent.setArtifactId( "test-artifact" );

    Model model = new Model();

    model.setParent( parent );
    model.setArtifactId( "real-artifact" );

    MavenProject project = new MavenProject( model );

    assertEquals( "groupId proto-inheritance failed.", "test-group", project.getGroupId() );
    assertEquals( "artifactId is masked.", "real-artifact", project.getArtifactId() );
    assertEquals( "version proto-inheritance failed.", "1000", project.getVersion() );

    // draw the NPE.
    project.getId();
}
项目:xapi    文件:MvnServiceDefault.java   
private void loadParent(IntTo<Out1Unsafe<Model>> stack, Parent parent) {
  if (parent == null) {
    return;
  }
  // parents we will add to the end of the lookup list
  stack.add(()->{
    final ArtifactResult parentArtifact = loadArtifact(
        parent.getGroupId(),
        parent.getArtifactId(),
        "",
        "pom",
        parent.getVersion()
    );
    final Model parentPom = loadPomFile(parentArtifact.getArtifact().getFile().getAbsolutePath());
    // If we have a parent, push a provider onto the search stack
    loadParent(stack, parentPom.getParent());
    return parentPom;
  });
}
项目:mule-tooling-incubator    文件:ParentPomLinkDetector.java   
private Parent getParent(IDocument doc) {
    Model model = null;
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    InputStream in = null;
    try {
        in = IOUtils.toInputStream(doc.get(), "UTF-8");
        model = mavenreader.read(in);
        return model.getParent();
    } catch (Exception ex) {

    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {

            }
        }
    }
    return null;
}
项目:butterfly    文件:PomChangeParent.java   
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    String details;
    Parent parent = model.getParent();

    if (parent == null) {
        String message = String.format("Pom file %s does not have a parent", getRelativePath());

        switch (ifNotPresent) {
            case Warn:
                return TOExecutionResult.warning(this, new TransformationOperationException(message));
            case NoOp:
                return TOExecutionResult.noOp(this, message);
            case Fail:
                // Fail is the default
            default:
                return TOExecutionResult.error(this, new TransformationOperationException(message));
        }
    }

    if(groupId != null && artifactId != null && version != null) {
        parent.setGroupId(groupId);
        parent.setArtifactId(artifactId);
        parent.setVersion(version);
        String newParent = parent.toString();
        details = String.format("Parent for POM file (%s) has been set to %s", relativePomFile, newParent);
    } else if (groupId == null && artifactId == null && version != null) {
        String oldVersion = parent.getVersion();
        parent.setVersion(version);
        details = String.format("Parent's version for POM file (%s) has been changed from %s to %s", relativePomFile, oldVersion, version);
    } else {
        // FIXME this should be in a pre-validation
        return TOExecutionResult.error(this, new TransformationOperationException("Invalid POM parent transformation operation"));
    }

    return TOExecutionResult.success(this, details);
}
项目:neoscada    文件:AbstractSetQualifierMojo.java   
private void checkNonRelativeParent ( final MavenProject project )
{
    if ( project.getModel ().getParent () == null )
    {
        // no parent
        return;
    }

    if ( project.getParentFile () != null )
    {
        // is a local parent
        return;
    }

    final Parent parent = project.getModel ().getParent ();

    final String prefix = String.format ( "%s:%s:", parent.getGroupId (), parent.getArtifactId () );
    for ( final String entry : this.forceUpdateParentQualifiers )
    {
        if ( entry.startsWith ( prefix ) )
        {
            final String qualifier = entry.substring ( prefix.length () );
            final String newVersion = makeVersion ( parent.getVersion (), qualifier );

            getLog ().info ( String.format ( "Force update parent of %s to %s -> %s", project.getId (), parent.getId (), newVersion ) );

            addChange ( project.getFile (), new ModelModifier () {

                @Override
                public boolean apply ( final Model model )
                {
                    model.getParent ().setVersion ( newVersion );
                    return true;
                }
            } );
        }
    }
}
项目:IodineToolkit    文件:ParentData.java   
public ParentData(File parentPom) {
    try {
        parent = new Parent();
        Model model = new MavenXpp3Reader().read(new FileReader(parentPom));
        parent.setVersion(model.getVersion());
        parent.setArtifactId(model.getArtifactId());
        parent.setGroupId(model.getGroupId());
    } catch (Exception e) {
        parent = null;
    }
}
项目:apache-maven-shade-plugin    文件:MavenJDOMWriter.java   
/**
 * Method updateParent
 *
 * @param value
 * @param element
 * @param counter
 * @param xmlTag
 */
protected void updateParent( Parent value, String xmlTag, Counter counter, Element element )
{
    boolean shouldExist = value != null;
    Element root = updateElement( counter, element, xmlTag, shouldExist );
    if ( shouldExist )
    {
        Counter innerCount = new Counter( counter.getDepth() + 1 );
        findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
        findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
        findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
        findAndReplaceSimpleElement( innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml" );
    }
}
项目:unleash-maven-plugin    文件:PomUtilTest.java   
@Test
public void testSetParentVersion() throws Exception {
  URL url = getClass().getResource(getClass().getSimpleName() + "/pom1.xml");
  File source;
  try {
    source = new File(url.toURI());
  } catch (URISyntaxException e) {
    source = new File(url.getPath());
  }

  DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  Document document = builder.parse(source);

  Model model = new Model();
  model.setGroupId("com.itemis.maven.plugins");
  model.setArtifactId("test-project-1");
  model.setVersion("1");
  Parent parent = new Parent();
  parent.setGroupId("com.itemis");
  parent.setArtifactId("org-parent");
  parent.setVersion("1");
  model.setParent(parent);

  String newVersion = "2";
  PomUtil.setParentVersion(model, document, newVersion);

  Assert.assertEquals(newVersion, getNode(document.getDocumentElement(), "parent/version").getTextContent());
  Assert.assertEquals(newVersion, model.getParent().getVersion());
}
项目:sonarqube-licensecheck    文件:LicenseFinder.java   
public static List<License> getLicenses(File filePath, String userSettings, String globalSettings)
{
    try
    {
        Model model = new MavenXpp3Reader().read(new FileInputStream(filePath));

        if (!model.getLicenses().isEmpty())
        {
            return model.getLicenses();
        }
        else
        {
            if (model.getParent() != null)
            {
                Parent parent = model.getParent();
                Dependency dependency =
                    new Dependency(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion(), null);
                return getLicenses(DirectoryFinder.getPomPath(dependency,
                    DirectoryFinder.getMavenRepsitoryDir(userSettings, globalSettings)),
                    userSettings, globalSettings);
            }
            else
            {
                return Collections.emptyList();
            }
        }

    }
    catch (Exception e)
    {
        LOGGER.warn("Could not parse Maven POM " + filePath, e);
        return Collections.emptyList();
    }
}
项目:release-maven-plugin-parent    文件:ContextFactoryTest.java   
@Test
public void hasNotChanged_VersionNotChanged() {
    final ReleasableModule module = mock(ReleasableModule.class);
    when(module.getGroupId()).thenReturn(ANY_GROUP_ID);
    when(module.getArtifactId()).thenReturn(ANY_ARTIFACT_ID);
    final Version version = mock(Version.class);
    when(module.getVersion()).thenReturn(version);
    when(reactor.findByLabel(ANY_GROUP_ID + ":" + ANY_ARTIFACT_ID)).thenReturn(module);
    final Parent parent = mock(Parent.class);
    when(parent.getGroupId()).thenReturn(ANY_GROUP_ID);
    when(parent.getArtifactId()).thenReturn(ANY_ARTIFACT_ID);
    assertTrue(context.hasNotChanged(parent));
}
项目:release-maven-plugin-parent    文件:ContextFactoryTest.java   
@Test
public void hasNotChanged_VersionChanged() {
    final ReleasableModule module = mock(ReleasableModule.class);
    when(module.getGroupId()).thenReturn(ANY_GROUP_ID);
    when(module.getArtifactId()).thenReturn(ANY_ARTIFACT_ID);
    final Version version = mock(Version.class);
    when(version.hasChanged()).thenReturn(true);
    when(module.getVersion()).thenReturn(version);
    when(reactor.findByLabel(ANY_GROUP_ID + ":" + ANY_ARTIFACT_ID)).thenReturn(module);
    final Parent parent = mock(Parent.class);
    when(parent.getGroupId()).thenReturn(ANY_GROUP_ID);
    when(parent.getArtifactId()).thenReturn(ANY_ARTIFACT_ID);
    assertFalse(context.hasNotChanged(parent));
}
项目:intellij-ce-playground    文件:Maven30AetherModelConverter.java   
public static MavenModel convertModelWithAetherDependencyTree(Model model,
                                                              List<String> sources,
                                                              List<String> testSources,
                                                              Collection<Artifact> dependencies,
                                                              Collection<DependencyNode> dependencyTree,
                                                              Collection<Artifact> extensions,
                                                              File localRepository) throws RemoteException {
  MavenModel result = new MavenModel();
  result.setMavenId(new MavenId(model.getGroupId(), model.getArtifactId(), model.getVersion()));

  Parent parent = model.getParent();
  if (parent != null) {
    result.setParent(new MavenParent(new MavenId(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()),
                                     parent.getRelativePath()));
  }
  result.setPackaging(model.getPackaging());
  result.setName(model.getName());
  result.setProperties(model.getProperties() == null ? new Properties() : model.getProperties());
  result.setPlugins(convertPlugins(model));

  Map<Artifact, MavenArtifact> convertedArtifacts = new THashMap<Artifact, MavenArtifact>();
  result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepository));
  result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepository));
  result.setDependencyTree(convertAetherDependencyNodes(null, dependencyTree, convertedArtifacts, localRepository));

  result.setRemoteRepositories(convertRepositories(model.getRepositories()));
  result.setProfiles(convertProfiles(model.getProfiles()));
  result.setModules(model.getModules());

  convertBuild(result.getBuild(), model.getBuild(), sources, testSources);
  return result;
}
项目:intellij-ce-playground    文件:Maven32AetherModelConverter.java   
public static MavenModel convertModelWithAetherDependencyTree(Model model,
                                                              List<String> sources,
                                                              List<String> testSources,
                                                              Collection<Artifact> dependencies,
                                                              Collection<DependencyNode> dependencyTree,
                                                              Collection<Artifact> extensions,
                                                              File localRepository) throws RemoteException {
  MavenModel result = new MavenModel();
  result.setMavenId(new MavenId(model.getGroupId(), model.getArtifactId(), model.getVersion()));

  Parent parent = model.getParent();
  if (parent != null) {
    result.setParent(new MavenParent(new MavenId(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()),
                                     parent.getRelativePath()));
  }
  result.setPackaging(model.getPackaging());
  result.setName(model.getName());
  result.setProperties(model.getProperties() == null ? new Properties() : model.getProperties());
  result.setPlugins(convertPlugins(model));

  Map<Artifact, MavenArtifact> convertedArtifacts = new THashMap<Artifact, MavenArtifact>();
  result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepository));
  result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepository));
  result.setDependencyTree(convertAetherDependencyNodes(null, dependencyTree, convertedArtifacts, localRepository));

  result.setRemoteRepositories(convertRepositories(model.getRepositories()));
  result.setProfiles(convertProfiles(model.getProfiles()));
  result.setModules(model.getModules());

  convertBuild(result.getBuild(), model.getBuild(), sources, testSources);
  return result;
}
项目:nexus-public    文件:MavenUploadHandlerTest.java   
@Test
public void testValidatPom_parentGroup() {
  Model model = new Model();
  model.setParent(new Parent());
  model.getParent().setGroupId("parentGroup");
  model.setArtifactId("testArtifact");
  model.setVersion("1.0");

  underTest.validatePom(model);
}
项目:nexus-public    文件:MavenUploadHandlerTest.java   
@Test
public void testValidatPom_parentVersion() {
  Model model = new Model();
  model.setParent(new Parent());
  model.getParent().setVersion("2.0");
  model.setGroupId("testGroup");
  model.setArtifactId("testArtifact");

  underTest.validatePom(model);
}
项目:tibco-bwmaven    文件:GenerateDeploymentPOM.java   
private Model addParent(Model model, String parentGroupId, String parentArtifactId, String parentVersion) {
    if (model == null) return null;

    Parent p = new Parent();
    p.setGroupId(parentGroupId);
    p.setArtifactId(parentArtifactId);
    p.setVersion(parentVersion);

    if (!(model.getGroupId()+":"+model.getArtifactId()).equals(parentGroupId+":"+parentArtifactId)) {
        model.setParent(p);
    }

    return model;
}
项目:flatten-maven-plugin    文件:FlattenModelResolver.java   
/**
 * Resolves the POM for the specified parent.
 *
 * @param parent the parent coordinates to resolve, must not be {@code null}
 * @return The source of the requested POM, never {@code null}
 * @since Apache-Maven-3.2.2 (MNG-5639)
 */
public ModelSource resolveModel( Parent parent )
        throws UnresolvableModelException {

    Dependency parentDependency = new Dependency();
    parentDependency.setGroupId(parent.getGroupId());
    parentDependency.setArtifactId(parent.getArtifactId());
    parentDependency.setVersion(parent.getVersion());
    parentDependency.setClassifier("");
    parentDependency.setType("pom");

    Artifact parentArtifact = null;
    try
    {
        Iterable<ArtifactResult> artifactResults = depencencyResolver.resolveDependencies(
                projectBuildingRequest, singleton(parentDependency), null, null );
        Iterator<ArtifactResult> iterator = artifactResults.iterator();
        if (iterator.hasNext()) {
            parentArtifact = iterator.next().getArtifact();
        }
    } catch (DependencyResolverException e) {
        throw new UnresolvableModelException( e.getMessage(), parent.getGroupId(), parent.getArtifactId(),
                parent.getVersion(), e );
    }

    return resolveModel( parentArtifact.getGroupId(), parentArtifact.getArtifactId(), parentArtifact.getVersion() );
}
项目:che    文件:MavenModelUtil.java   
public static MavenModel convertModel(
    Model model,
    File projectDir,
    List<String> sources,
    List<String> testSources,
    Collection<Artifact> dependencies,
    Collection<Artifact> extensions,
    File localRepo) {

  MavenModel result = new MavenModel();
  result.setMavenKey(new MavenKey(model.getGroupId(), model.getArtifactId(), model.getVersion()));

  Parent parent = model.getParent();
  if (parent != null) {
    result.setParent(
        new MavenParent(
            new MavenKey(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()),
            parent.getRelativePath()));
  }

  result.setName(model.getName());
  result.setPackaging(model.getPackaging());
  result.setProperties(model.getProperties() != null ? model.getProperties() : new Properties());
  result.setModules(model.getModules());
  result.setPlugins(convertPlugins(model));

  Map<Artifact, MavenArtifact> convertedArtifacts = new HashMap<>();

  result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepo));
  result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepo));

  result.setRemoteRepositories(convertRepositories(model.getRepositories()));
  result.setProfiles(convertProfiles(model.getProfiles(), projectDir));
  convertBuild(result.getBuild(), model.getBuild(), projectDir, sources, testSources);

  return result;
}
项目:che    文件:MavenModelUtil.java   
public static Model convertToMavenModel(MavenModel model, File projectDir) {
  Model result = new Model();
  result.setArtifactId(model.getMavenKey().getArtifactId());
  result.setGroupId(model.getMavenKey().getGroupId());
  result.setVersion(model.getMavenKey().getVersion());
  result.setPackaging(model.getPackaging());
  result.setName(model.getName());

  if (model.getParent() != null) {
    Parent parent = new Parent();
    MavenKey parentKey = model.getParent().getMavenKey();
    parent.setArtifactId(parentKey.getArtifactId());
    parent.setGroupId(parentKey.getGroupId());
    parent.setVersion(parentKey.getVersion());
    parent.setRelativePath(model.getParent().getRelativePath());
    result.setParent(parent);
  }

  result.setProperties(model.getProperties());
  result.setModules(model.getModules());
  result.setBuild(new Build());
  MavenBuild modelBuild = model.getBuild();
  convertToMavenBuildBase(modelBuild, result.getBuild(), projectDir);
  result.getBuild().setSourceDirectory(relativize(projectDir, modelBuild.getSources().get(0)));
  result
      .getBuild()
      .setTestSourceDirectory(relativize(projectDir, modelBuild.getTestSources().get(0)));

  result.getBuild().setOutputDirectory(modelBuild.getOutputDirectory());
  result.getBuild().setTestOutputDirectory(modelBuild.getTestOutputDirectory());

  result.setProfiles(convertToMavenProfiles(model.getProfiles(), projectDir));
  return result;
}
项目:versions-maven-plugin    文件:AbstractVersionsDependencyUpdaterMojo.java   
protected Artifact toArtifact( Parent model )
    throws MojoExecutionException
{
    Dependency d = new Dependency();
    d.setArtifactId( model.getArtifactId() );
    d.setGroupId( model.getGroupId() );
    d.setVersion( model.getVersion() );
    d.setType( "pom" );
    d.setScope( Artifact.SCOPE_COMPILE );
    return this.toArtifact( d );
}
项目:msf4j    文件:MSF4JArtifactProjectNature.java   
/**
 * Update created pom.xml file with necessary dependencies and plug-ins so
 * that it works with WSO2 MSF4J server
 * 
 * @throws IOException
 * @throws XmlPullParserException
 *
 */
private void updatePom(IProject project) throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = project.getFile(POM_FILE).getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    Parent msf4jParent = new Parent();
    msf4jParent.setGroupId(MSF4J_SERVICE_PARENT_GROUP_ID);
    msf4jParent.setArtifactId(MSF4J_SERVICE_PARENT_ARTIFACT_ID);
    msf4jParent.setVersion(MSF4JArtifactConstants.getMSF4JServiceParentVersion());
    mavenProject.getModel().setParent(msf4jParent);

    Properties generatedProperties = mavenProject.getModel().getProperties();
    generatedProperties.clear();

}
项目:artifactory    文件:PomTargetPathValidator.java   
private String getGroupId(Model model) {
    String groupId = model.getGroupId();
    if (StringUtils.isBlank(groupId)) {
        Parent parent = model.getParent();
        if (parent != null) {
            groupId = parent.getGroupId();
        }
    }
    return groupId;
}