private void checkOnNoDependencieVersionsFrom3rdParty(MavenProject project) throws EnforcerRuleException { Model originalModel = project.getOriginalModel(); StringBuilder dependenciesWithVersionDeclaration = new StringBuilder(); if (project.getGroupId().equals(ignoreMasterProjectGroupId) || originalModel.getDependencyManagement() == null || originalModel.getDependencyManagement().getDependencies() == null) { return; } boolean fail = false; for (Dependency d : originalModel.getDependencyManagement().getDependencies()) { if (!d.getGroupId().startsWith(allowedGroupPrefix)) { dependenciesWithVersionDeclaration.append(" - " + d.toString() + "\n"); fail = true; } } if (fail) { throw new EnforcerRuleException( "This Project contains Dependency-Versions from 3rd party libs (not " + allowedGroupPrefix + ").\n" + "Please declare for maintainance reasons 3rd pary versions in " + ignoreMasterProjectGroupId + ".\n" + "This dependencies sould be corrected:\n" + dependenciesWithVersionDeclaration); } }
public void testAddExclusion_existingExclusion() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project><dependencies>" + // "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAA</groupId><artifactId>BBBB</artifactId><version>1.0</version>" + // "<exclusions><exclusion><groupId>g</groupId><artifactId>b</artifactId><version>1.0</version></exclusion></exclusions></dependency>" + // "</dependencies></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 1, dependencyCount(tempModel, d)); assertTrue( "Has exclusion " + e.toString() + "\n" + document.getText(), hasExclusion(tempModel, d, e)); ArtifactKey key = new ArtifactKey("g", "b", "1.0", null); assertTrue( "Existing Exclusion Present " + key.toString() + "\n" + document.getText(), hasExclusion(tempModel, d, key)); assertEquals("Exclusions", 2, getExclusionCount(tempModel, d)); assertEquals("Dependency Count: \n" + document.getText(), 3, getDependencyCount(tempModel)); }
public void testMissingDependency_noDependenciesElement() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d)); }
public void testMissingDependency_withDependencies() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project><dependencies>" + // "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "</dependencies></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d)); assertEquals("Dependency Count: \n" + document.getText(), 2, getDependencyCount(tempModel)); }
private void checkOnNoDependencieVersion(MavenProject project) throws EnforcerRuleException { Model originalModel = project.getOriginalModel(); StringBuilder dependenciesWithVersionDeclaration = new StringBuilder(); boolean fail = false; for (Dependency d : originalModel.getDependencies()) { if (d.getVersion() != null) { dependenciesWithVersionDeclaration.append(" - " + d.toString() + "\n"); fail = true; } } if (fail) { throw new EnforcerRuleException( "This project contains explicit dependeny versions.\n" + "Please declare for maintainance reasons 3rd pary versions in " + ignoreMasterProjectGroupId + " or\n" + "in case of bei '" + allowedGroupPrefix + "*' Libs in the root pom in the 'dependencyManagement' section.\n" + "This dependencies sould be corrected:\n" + dependenciesWithVersionDeclaration); } }