/** 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(); }
/** * Method updateDeveloper * * @param value * @param element * @param counter * @param xmlTag */ protected void updateDeveloper( Developer value, String xmlTag, Counter counter, Element element ) { Element root = element; Counter innerCount = new Counter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null ); findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null ); findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null ); findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null ); findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null ); findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null ); findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" ); findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null ); findAndReplaceProperties( innerCount, root, "properties", value.getProperties() ); }
private void visitDeveloper( ModelVisitor visitor, Developer developer ) { List<String> roles = developer.getRoles(); if ( roles != null ) { ListIterator<String> roleIterator = roles.listIterator(); while ( roleIterator.hasNext() ) { String role = roleIterator.next(); visitor.visitDeveloperRole( role ); role = visitor.replaceDeveloperRole( role ); if ( role == null ) roleIterator.remove(); else roleIterator.set( role ); } } Properties properties = developer.getProperties(); if ( properties != null ) { Iterator<Entry<Object, Object>> propertyIterator = properties.entrySet().iterator(); while ( propertyIterator.hasNext() ) { Entry<Object, Object> property = propertyIterator.next(); String propertyKey = (String) property.getKey(); String propertyValue = (String) property.getKey(); visitor.visitDeveloperProperty( propertyKey, propertyValue ); propertyValue = visitor.replaceDeveloperProperty( propertyKey, propertyValue ); if ( propertyValue == null ) propertyIterator.remove(); else property.setValue( propertyValue ); } } }
private void addProjectHavingAnArchitectAsDeveloperAndABusinessEngineerAsContributorToHelper() throws Exception { final MavenProject mavenProject = new MavenProject(); final Developer developer = new Developer(); developer.addRole( "architect" ); mavenProject.addDeveloper( developer ); final Contributor contributor = new Contributor(); contributor.addRole( "business engineer" ); mavenProject.addContributor( contributor ); Mockito.when( helper.evaluate( "${project}" ) ).thenReturn( mavenProject ); }
private String createDefaultLicenseHeader() { String organization = ""; Organization org = project.getOrganization(); if (org != null) { organization = org.getName(); } if (organization == null) { List devs = project.getDevelopers(); if (devs.size() > 0) { Iterator dvs = devs.iterator(); String devsString = ""; while (dvs.hasNext()) { Developer d = ( Developer )dvs.next(); devsString = devsString + "," + d.getName() != null ? d.getName() : d.getId(); } organization = devsString.substring( 1 ); } } if (organization == null) { organization = ""; //what's a good default value? } String date = ""; if (project.getInceptionYear() != null) { date = project.getInceptionYear(); } String year = Integer.toString( Calendar.getInstance().get( Calendar.YEAR )); if (!year.equals( date ) ) { date = date.length() == 0 ? year : date + "-" + year; } return "Copyright " + organization + " " + date; }
protected void mergeDeveloper_Id( Developer target, Developer source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getId(); if ( src != null ) { if ( sourceDominant || target.getId() == null ) { target.setId( src ); target.setLocation( "id", source.getLocation( "id" ) ); } } }
@Override protected void mergeModel_Developers( Model target, Model source, boolean sourceDominant, Map<Object, Object> context ) { if ( target.getDevelopers().isEmpty() ) { target.setDevelopers( new ArrayList<Developer>( source.getDevelopers() ) ); } }
@Test public void shouldUseTemplateIfProvided() throws Exception { MavenPublishable withoutTemplate = createMavenPublishable("//example:no-template", "example.com:project:1.0.0", null); Model noTemplate = parse(Pom.generatePomFile(pathResolver, withoutTemplate)); MavenPublishable withTemplate = createMavenPublishable( "//example:template", "example.com:project:1.0.0", FakeSourcePath.of( TestDataHelper.getTestDataDirectory(getClass()) .resolve("poms/template-pom.xml") .toString())); Model templated = parse(Pom.generatePomFile(pathResolver, withTemplate)); // Template sets developers and an example dep. Check that these aren't in the non-templated // version assertTrue(noTemplate.getDevelopers().isEmpty()); assertTrue(noTemplate.getDependencies().isEmpty()); // Now check the same fields in the templated version. Developer seenDev = Iterables.getOnlyElement(templated.getDevelopers()); assertEquals("susan", seenDev.getId()); assertEquals("Susan The Developer", seenDev.getName()); assertEquals(ImmutableList.of("Owner"), seenDev.getRoles()); Dependency seenDep = Iterables.getOnlyElement(templated.getDependencies()); assertEquals("com.google.guava", seenDep.getGroupId()); assertEquals("guava", seenDep.getArtifactId()); assertEquals("19.0", seenDep.getVersion()); }
@Override public Developer replaceDeveloper( Developer developer ) { return developer; }
@Override public void visitDeveloper( Developer developer ) { }
/** * @param units contributors and developers to check * @return required headers */ private Map<String, Boolean> checkRequiredHeaders( List<? extends Contributor> units ) { Map<String, Boolean> requiredHeaders = new HashMap<String, Boolean>(); requiredHeaders.put( IMAGE, Boolean.FALSE ); requiredHeaders.put( ID, Boolean.FALSE ); requiredHeaders.put( NAME, Boolean.FALSE ); requiredHeaders.put( EMAIL, Boolean.FALSE ); requiredHeaders.put( URL, Boolean.FALSE ); requiredHeaders.put( ORGANIZATION, Boolean.FALSE ); requiredHeaders.put( ORGANIZATION_URL, Boolean.FALSE ); requiredHeaders.put( ROLES, Boolean.FALSE ); requiredHeaders.put( TIME_ZONE, Boolean.FALSE ); requiredHeaders.put( PROPERTIES, Boolean.FALSE ); for ( Contributor unit : units ) { if ( unit instanceof Developer ) { Developer developer = (Developer) unit; if ( StringUtils.isNotEmpty( developer.getId() ) ) { requiredHeaders.put( ID, Boolean.TRUE ); } } if ( StringUtils.isNotEmpty( unit.getName() ) ) { requiredHeaders.put( NAME, Boolean.TRUE ); } if ( StringUtils.isNotEmpty( unit.getEmail() ) ) { requiredHeaders.put( EMAIL, Boolean.TRUE ); requiredHeaders.put( IMAGE, Boolean.TRUE ); } if ( StringUtils.isNotEmpty( unit.getUrl() ) ) { requiredHeaders.put( URL, Boolean.TRUE ); } if ( StringUtils.isNotEmpty( unit.getOrganization() ) ) { requiredHeaders.put( ORGANIZATION, Boolean.TRUE ); } if ( StringUtils.isNotEmpty( unit.getOrganizationUrl() ) ) { requiredHeaders.put( ORGANIZATION_URL, Boolean.TRUE ); } if ( !isEmpty( unit.getRoles() ) ) { requiredHeaders.put( ROLES, Boolean.TRUE ); } if ( StringUtils.isNotEmpty( unit.getTimezone() ) ) { requiredHeaders.put( TIME_ZONE, Boolean.TRUE ); } Properties properties = unit.getProperties(); boolean hasPicUrl = properties.containsKey( "picUrl" ); if ( hasPicUrl ) { requiredHeaders.put( IMAGE, Boolean.TRUE ); } boolean isJustAnImageProperty = properties.size() == 1 && hasPicUrl; if ( !isJustAnImageProperty && !properties.isEmpty() ) { requiredHeaders.put( PROPERTIES, Boolean.TRUE ); } } return requiredHeaders; }
@Override protected List<Developer> getRoles( MavenProject mavenProject ) { return mavenProject.getDevelopers(); }
@Override public List<Developer> get( Model model ) { return model.getDevelopers(); }
@Override public void set( Model model, List<Developer> value ) { model.setDevelopers( value ); }
protected InfoDescriptor createInfoDescriptor( InfoDescriptor info ) { if ( this.project == null ) { return info; } if ( info.getVersion() == null ) { info.setVersion( this.project.getVersion() ); } if ( info.getTitle() == null ) { info.setTitle( this.project.getArtifactId() ); } if ( info.getDescription() == null ) { info.setDescription( this.project.getDescription() ); } ContactDescriptor contact = info.getContact(); if ( contact == null ) { Organization organization = this.project.getOrganization(); if ( organization != null ) { contact = new ContactDescriptor(); contact.setUrl( organization.getUrl() ); contact.setName( organization.getName() ); info.setContact( contact ); } else { String url = Util.getTrimmed( this.project.getUrl() ); if ( !url.isEmpty() ) { contact = new ContactDescriptor(); contact.setUrl( url ); String name = Util.getTrimmed( this.project.getName() ); if ( name.isEmpty() ) { name = Util.getTrimmed( this.project.getArtifactId() ); } contact.setName( name ); info.setContact( contact ); } else { List<Developer> developers = this.project.getDevelopers(); if ( ( developers != null ) && ( !developers.isEmpty() ) ) { contact = new ContactDescriptor(); Developer developer = developers.get( 0 ); contact.setUrl( Util.getTrimmed( developer.getUrl() ) ); contact.setEmail( Util.getTrimmed( developer.getEmail() ) ); contact.setName( Util.getTrimmed( developer.getName() ) ); info.setContact( contact ); } } } } LicenseDescriptor serviceLicense = info.getLicense(); if ( serviceLicense == null ) { List<org.apache.maven.model.License> licenses = this.project.getLicenses(); if ( ( licenses != null ) && ( !licenses.isEmpty() ) ) { serviceLicense = new LicenseDescriptor(); org.apache.maven.model.License projectLicense = licenses.get( 0 ); serviceLicense.setName( projectLicense.getName() ); serviceLicense.setUrl( projectLicense.getUrl() ); info.setLicense( serviceLicense ); } } return info; }
/** * Method iterateDeveloper * * @param counter * @param childTag * @param parentTag * @param list * @param parent */ protected void iterateDeveloper( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag ) { boolean shouldExist = list != null && list.size() > 0; Element element = updateElement( counter, parent, parentTag, shouldExist ); if ( shouldExist ) { Iterator it = list.iterator(); Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator(); if ( !elIt.hasNext() ) { elIt = null; } Counter innerCount = new Counter( counter.getDepth() + 1 ); while ( it.hasNext() ) { Developer value = (Developer) it.next(); Element el; if ( elIt != null && elIt.hasNext() ) { el = (Element) elIt.next(); if ( !elIt.hasNext() ) { elIt = null; } } else { el = factory.element( childTag, element.getNamespace() ); insertAtPreferredLocation( element, el, innerCount ); } updateDeveloper( value, childTag, innerCount, el ); innerCount.increaseCount(); } if ( elIt != null ) { while ( elIt.hasNext() ) { elIt.next(); elIt.remove(); } } } }
public void setDevelopers( List<Developer> developers ) { getModel().setDevelopers( developers ); }
public List<Developer> getDevelopers() { return getModel().getDevelopers(); }
public void addDeveloper( Developer developer ) { getModel().addDeveloper( developer ); }
protected void mergeDeveloper( Developer target, Developer source, boolean sourceDominant, Map<Object, Object> context ) { mergeContributor( target, source, sourceDominant, context ); mergeDeveloper_Id( target, source, sourceDominant, context ); }
protected Object getDeveloperKey( Developer object ) { return object; }
@Override public void addDeveloper(final Developer developer) { getDelegate().addDeveloper(developer); }
public void addDeveloper( Developer developer ) { }
/** Replies the list of developers. * * @return the list of developers. */ public List<? extends Developer> getDevelopers() { return this.developers == null ? Collections.<Developer>emptyList() : this.developers; }
Developer replaceDeveloper( Developer developer );
void visitDeveloper( Developer developer );