private void writeScm(Scm scm, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if (scm.getConnection() != null) { writeValue(serializer, "connection", scm.getConnection(), scm); } if (scm.getDeveloperConnection() != null) { writeValue(serializer, "developerConnection", scm.getDeveloperConnection(), scm); } if ((scm.getTag() != null) && !scm.getTag().equals("HEAD")) { writeValue(serializer, "tag", scm.getTag(), scm); } if (scm.getUrl() != null) { writeValue(serializer, "url", scm.getUrl(), scm); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(scm, "", start, b.length()); }
/** * Method updateScm * * @param value * @param element * @param counter * @param xmlTag */ protected void updateScm( Scm value, String xmlTag, Counter counter, Element element ) { boolean shouldExist = value != null; Element root = updateElement( counter, element, xmlTag, shouldExist ); if ( shouldExist ) { //CHECKSTYLE_OFF: LineLength Counter innerCount = new Counter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, root, "connection", value.getConnection(), null ); findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(), null ); findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" ); findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null ); //CHECKSTYLE_ON: LineLength } }
@Test @UseDataProvider("calcProviderName") public void testCalcProviderName(String devConnection, String connection, String expectedProviderName) { MavenProject p = new MavenProject(); p.setScm(new Scm()); p.getScm().setDeveloperConnection(devConnection); p.getScm().setConnection(connection); Optional<String> providerName = MavenScmUtil.calcProviderName(p); if (expectedProviderName == null) { Assert.assertFalse(providerName.isPresent()); } else { Assert.assertTrue(providerName.isPresent()); Assert.assertEquals(expectedProviderName, providerName.get()); } }
@Override public void initialize() throws PluginException { final Scm scm = getProject().getScm(); if (scm != null) { remoteUrlOrNull = scm.getDeveloperConnection(); if (remoteUrlOrNull == null) { remoteUrlOrNull = scm.getConnection(); } if (remoteUrlOrNull != null) { if (!remoteUrlOrNull.startsWith(GIT_PREFIX)) { throw new PluginException(ERROR_SUMMARY).add("The value in your scm tag is %s", remoteUrlOrNull); } remoteUrlOrNull = remoteUrlOrNull.substring(GIT_PREFIX.length()).replace("file://localhost/", "file:///"); } } }
protected static String getRemoteUrlOrNullIfNoneSet(Scm originalScm, Scm actualScm) throws ValidationException { if (originalScm == null) { // No scm was specified, so don't inherit from any parent poms as they are probably used in different git repos return null; } // There is an SCM specified, so the actual SCM with derived values is used in case (so that variables etc are interpolated) String remote = actualScm.getDeveloperConnection(); if (remote == null) { remote = actualScm.getConnection(); } if (remote == null) { return null; } return GitHelper.scmUrlToRemote(remote); }
@Override protected void update(ModifiedPomXMLEventReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { try { Model model = PomHelper.getRawModel( pom ); Scm scm = model.getScm(); if (scm == null) { throw new MojoFailureException( "No <scm> was present" ); } getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag ); boolean success = PomHelper.setProjectValue(pom, "/project/scm/tag", newTag ); if ( !success ) { throw new MojoFailureException( "Could not update the SCM tag" ); } } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
/** * Lookup source code configuration or default to SCM. * * @param project project * @param log log * @return source code url or null */ protected static String getSourceCode(MavenProject project, Log log) { Plugin nbmPlugin = lookupNbmPlugin(project); if (nbmPlugin != null) { Xpp3Dom config = (Xpp3Dom) nbmPlugin.getConfiguration(); if (config != null && config.getChild("sourceCodeUrl") != null) { return config.getChild("sourceCodeUrl").getValue(); } } Scm scm = project.getScm(); if (scm != null && scm.getUrl() != null && !scm.getUrl().isEmpty()) { log.debug("SCM configuration found, with url = '" + scm.getUrl() + "'"); return scm.getUrl(); } else { } return null; }
/** * 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; }
@Override protected void mergeScm_Url( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getUrl(); if ( src != null ) { if ( sourceDominant ) { target.setUrl( src ); target.setLocation( "url", source.getLocation( "url" ) ); } else if ( target.getUrl() == null ) { target.setUrl( appendPath( src, context ) ); target.setLocation( "url", source.getLocation( "url" ) ); } } }
@Override protected void mergeScm_Connection( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getConnection(); if ( src != null ) { if ( sourceDominant ) { target.setConnection( src ); target.setLocation( "connection", source.getLocation( "connection" ) ); } else if ( target.getConnection() == null ) { target.setConnection( appendPath( src, context ) ); target.setLocation( "connection", source.getLocation( "connection" ) ); } } }
@Override protected void mergeScm_DeveloperConnection( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getDeveloperConnection(); if ( src != null ) { if ( sourceDominant ) { target.setDeveloperConnection( src ); target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } else if ( target.getDeveloperConnection() == null ) { target.setDeveloperConnection( appendPath( src, context ) ); target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } } }
public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception { Model model = new Model(); Scm scm = new Scm(); scm.setConnection( "${test}/somepath" ); model.setScm( scm ); ModelInterpolator interpolator = createInterpolator(); final SimpleProblemCollector collector = new SimpleProblemCollector(); Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); assertProblemFree( collector ); assertEquals( "${test}/somepath", out.getScm().getConnection() ); }
public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception { Model model = new Model(); Scm scm = new Scm(); scm.setConnection( "${project.scm.connection}/somepath" ); model.setScm( scm ); try { ModelInterpolator interpolator = createInterpolator(); final SimpleProblemCollector collector = new SimpleProblemCollector(); interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector ); assertColllectorState( 0, 1, 0, collector ); } catch ( Exception e ) { } }
/** Constructor. * @param artifact the artifact. * @param name name of the artifact. * @param website website. * @param organization organization. * @param scmRevision url of the SCM. * @param scm SCM. * @param developers developers. * @param contributors constributors. * @param licenses licenses. */ public ExtendedArtifact( Artifact artifact, String name, String website, Organization organization, String scmRevision, Scm scm, List<? extends Developer> developers, List<? extends Contributor> contributors, List<? extends License> licenses) { this.original = artifact; this.artifactName = name; this.developers = developers; this.contributors = contributors; this.website = website; this.organization = organization; this.scm = scm; this.scmRevision = scmRevision; this.licenses = licenses; }
@Test public void shouldNotFindBestPracticesViolation() { License license = new License(); license.setName("license-name"); license.setUrl("license-url"); Developer developer = new Developer(); developer.setId("dev-id"); developer.setName("dev-name"); Scm scm = new Scm(); scm.setUrl("scm-url"); scm.setConnection("scm-connection"); PomBuilder pomBuilder = pom(); pomBuilder.model().setName("foo-name"); pomBuilder.model().setDescription(""); // empty description is allowed, see WOLF-69 pomBuilder.model().setUrl("foo-url"); pomBuilder.model().addLicense(license); pomBuilder.model().addDeveloper(developer); pomBuilder.model().setScm(scm); pomBuilder.create(repoFooDir); validationExecutor.execute(ctx); assertSuccess(); }
private Scm getScm() { Iterator<? extends MavenProject> prj = result.allInstances().iterator(); if (!prj.hasNext()) { return null; } MavenProject project = prj.next(); return project.getScm(); }
protected String getOrFindGitUrl(UIExecutionContext context, String gitUrlText) { if (Strings.isNullOrBlank(gitUrlText)) { final Project project = getSelectedProject(context); if (project != null) { Resource<?> root = project.getRoot(); if (root != null) { try { Resource<?> gitFolder = root.getChild(".git"); if (gitFolder != null) { Resource<?> config = gitFolder.getChild("config"); if (config != null) { String configText = config.getContents(); gitUrlText = GitHelpers.extractGitUrl(configText); } } } catch (Exception e) { log.debug("Ignoring missing git folders: " + e, e); } } } } if (Strings.isNullOrBlank(gitUrlText)) { Model mavenModel = getMavenModel(context); if (mavenModel != null) { Scm scm = mavenModel.getScm(); if (scm != null) { String connection = scm.getConnection(); if (Strings.isNotBlank(connection)) { gitUrlText = connection; } } } } if (Strings.isNullOrBlank(gitUrlText)) { throw new IllegalArgumentException("Could not find git URL"); } return gitUrlText; }
private org.apache.archiva.metadata.model.Scm convertScm( Scm scm ) { org.apache.archiva.metadata.model.Scm newScm = null; if ( scm != null ) { newScm = new org.apache.archiva.metadata.model.Scm(); newScm.setConnection( scm.getConnection() ); newScm.setDeveloperConnection( scm.getDeveloperConnection() ); newScm.setUrl( scm.getUrl() ); } return newScm; }
public void revertScmSettings(MavenProject projectToRevert, Document document) { Scm scm = this.metadata.getCachedScmSettings(projectToRevert); if (scm != null) { this.log.debug("\t\tReversion of SCM connection tags"); Document originalPOM = this.metadata.getCachedOriginalPOM(projectToRevert); Node scmNode = PomUtil.getOrCreateScmNode(document, false); Node originalScmNode = PomUtil.getOrCreateScmNode(originalPOM, false); if (scmNode != null) { Optional<String> connection = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_CONNECTION); if (connection.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION, connection.get(), false); } Optional<String> devConnection = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION); if (devConnection.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION, devConnection.get(), false); } Optional<String> url = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_URL); if (url.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL, url.get(), false); } if (scm.getTag() != null) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_TAG, scm.getTag(), false); } else { PomUtil.deleteNode(scmNode, PomUtil.NODE_NAME_SCM_TAG); } } } }
/** * Derives the name of the required SCM provider from the given Maven project by analyzing the scm connection strings * of the project. * * @param project the project from which the SCM provider is retrieved. * @return the name of the required SCM provider. */ public static Optional<String> calcProviderName(MavenProject project) { String providerName = null; Scm scm = project.getScm(); if (scm != null) { // takes the developer connection first or the connection url if devConnection is empty or null String connection = StringUtils.trimToNull(scm.getDeveloperConnection()); connection = connection != null ? connection : StringUtils.trimToNull(scm.getConnection()); // scm url format description: https://maven.apache.org/scm/scm-url-format.html if (connection != null) { // cuts the substring "scm:" at the beginning connection = connection.substring(4); // as stated in the scm url format description, the provider delimiter may be a colon (:) or a pipe (|) if // colons are used otherwise (e.g. for windows paths) // svn:http://... -> svn:http://... // svn|http://... -> svn // svn:http://xyz|... -> svn:http://xyz int nextPipe = connection.indexOf('|'); if (nextPipe > -1) { connection = connection.substring(0, nextPipe); } // svn -> svn // svn:http... -> svn int nextColon = connection.indexOf(':'); if (nextColon > -1) { providerName = connection.substring(0, nextColon); } else { providerName = connection; } } } return Optional.fromNullable(providerName); }
/** * Appends the given {@code project} to the given {@code ancestryPath} and returns the same instance of * {@code ancestryPath}. * * @param project * the project to append * @param ancestryPath * the path to append to * @return the given {@code ancestryPath} */ private static List<Element> append(MavenProject project, List<Element> ancestryPath) { Scm scm = project.getScm(); if (scm == null) { log.debug("No SCM in project [{}:{}:{}]", project.getGroupId(), project.getArtifactId(), project.getVersion()); return ancestryPath; } else { String url = scm.getConnection(); if (url == null) { url = scm.getDeveloperConnection(); if (url == null) { log.debug("No SCM connection in project [{}:{}:{}]", project.getGroupId(), project.getArtifactId(), project.getVersion()); return ancestryPath; } else { log.debug("No SCM connection in project [{}:{}:{}] - falling back to developerConnection", project.getGroupId(), project.getArtifactId(), project.getVersion()); } } /* * url != null look if can climb up to the parent and shothen the URL */ ancestryPath.add(new Element(url, new Ga(project.getGroupId(), project.getArtifactId()))); MavenProject parent = project.getParent(); if (parent != null) { return append(parent, ancestryPath); } else { /* parent == null */ return ancestryPath; } } }
private ScmRepositoryIndex(MavenSession session, RepositorySystemSession repoSession, ArtifactFactory repositorySystem, ProjectBuilder projectBuilder, Set<org.srcdeps.core.Scm> scms) { super(); this.session = session; this.repoSession = repoSession; this.repositorySystem = repositorySystem; this.projectBuilder = projectBuilder; this.remoteRepos = RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories()); this.scms = scms; }
/** * @param url * the URL to decide about * @return {@code true} if the present version of srcdeps is able to handle the source management system given * by the {@code url} parameter */ private boolean isScmUrlSupported(String url) { for (org.srcdeps.core.Scm scm : scms) { if (scm.supports(url)) { return true; } } return false; }
/** * Method updateScm * * @param value * @param element * @param counter * @param xmlTag */ protected void updateScm( Scm 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, "connection", value.getConnection(), null ); findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(), null ); findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" ); findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null ); } }
/** * Mock it. * @return The mock * @throws Exception If something wrong happens inside */ public MavenProject mock() throws Exception { Mockito.doReturn("jar").when(this.project).getPackaging(); final Scm scm = new Scm(); scm.setConnection("scm:svn:..."); Mockito.doReturn(scm).when(this.project).getScm(); return this.project; }
protected void mergeScm( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { mergeScm_Url( target, source, sourceDominant, context ); mergeScm_Connection( target, source, sourceDominant, context ); mergeScm_DeveloperConnection( target, source, sourceDominant, context ); mergeScm_Tag( target, source, sourceDominant, context ); }
protected void mergeScm_Url( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getUrl(); if ( src != null ) { if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); target.setLocation( "url", source.getLocation( "url" ) ); } } }
protected void mergeScm_Connection( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getConnection(); if ( src != null ) { if ( sourceDominant || target.getConnection() == null ) { target.setConnection( src ); target.setLocation( "connection", source.getLocation( "connection" ) ); } } }
protected void mergeScm_DeveloperConnection( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getDeveloperConnection(); if ( src != null ) { if ( sourceDominant || target.getDeveloperConnection() == null ) { target.setDeveloperConnection( src ); target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } } }
protected void mergeScm_Tag( Scm target, Scm source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getTag(); if ( src != null ) { if ( sourceDominant || target.getTag() == null ) { target.setTag( src ); target.setLocation( "tag", source.getLocation( "tag" ) ); } } }
public void normalize( Model model, ModelBuildingRequest request ) { if ( model == null ) { return; } model.setUrl( normalize( model.getUrl() ) ); Scm scm = model.getScm(); if ( scm != null ) { scm.setUrl( normalize( scm.getUrl() ) ); scm.setConnection( normalize( scm.getConnection() ) ); scm.setDeveloperConnection( normalize( scm.getDeveloperConnection() ) ); } DistributionManagement dist = model.getDistributionManagement(); if ( dist != null ) { Site site = dist.getSite(); if ( site != null ) { site.setUrl( normalize( site.getUrl() ) ); } } }
public Scm getScm() { return null; }
public Scm getCachedScmSettings(MavenProject p) { return this.cachedScmSettings.get(ProjectToCoordinates.EMPTY_VERSION.apply(p)); }
private void updateScmConnections(String scmTagName) throws MojoFailureException { for (MavenProject p : this.reactorProjects) { Scm scm = p.getModel().getScm(); if (scm != null) { this.log.debug("\tUpdating SCM connection tags in POM of module '" + ProjectToString.INSTANCE.apply(p) + "'"); Optional<Document> parsedPOM = PomUtil.parsePOM(p); if (parsedPOM.isPresent()) { this.cachedPOMs.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), parsedPOM.get()); try { // parse again to not modify the cached object Document document = PomUtil.parsePOM(p).get(); Node scmNode = PomUtil.getOrCreateScmNode(document, false); if (scmNode != null) { Optional<String> connection = PomUtil.getChildNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION); if (connection.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION, this.scmProvider.calculateTagConnectionString(connection.get(), scmTagName), false); } Optional<String> devConnection = PomUtil.getChildNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION); if (devConnection.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION, this.scmProvider.calculateTagConnectionString(devConnection.get(), scmTagName), false); } Optional<String> url = PomUtil.getChildNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL); if (url.isPresent()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL, this.scmProvider.calculateTagConnectionString(url.get(), scmTagName), false); } if (!this.scmProvider.isTagInfoIncludedInConnection()) { PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_TAG, scmTagName, true); } PomUtil.writePOM(document, p); } } catch (Throwable t) { throw new MojoFailureException("Could not update scm information for release.", t); } } } } }
@Inject public SrcdepsInitMojo(Set<org.srcdeps.core.Scm> scms) { super(); this.scms = scms; }
@Override public Scm replaceScm( Scm scm ) { return scm; }
@Override public void visitScm( Scm scm ) { }
@Override public void renderBody() { Scm scm = model.getScm(); if (scm == null || StringUtils.isEmpty(anonymousConnection) && StringUtils.isEmpty(devConnection) && StringUtils.isEmpty(scm.getUrl())) { startSection(getTitle()); paragraph(getI18nString("noscm")); endSection(); return; } // fix issue #141 startSection( "Source Control Management"); ScmRepository anonymousRepository = getScmRepository(anonymousConnection); ScmRepository devRepository = getScmRepository(devConnection); // Overview section renderOverviewSection(anonymousRepository, devRepository); // Web access section renderWebAccessSection(webAccessUrl); // Anonymous access section if needed renderAnonymousAccessSection(anonymousRepository); // Developer access section renderDeveloperAccessSection(devRepository); // Access from behind a firewall section if needed renderAccessBehindFirewallSection(devRepository); // Access through a proxy section if needed renderAccessThroughProxySection(anonymousRepository, devRepository); endSection(); }
@Override public Scm get( Model model ) { return model.getScm(); }
@Override public void set( Model model, Scm value ) { model.setScm( value ); }