use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.
the class JavadocReportTest method testStylesheetfile.
/**
* Method to test the <code><stylesheetfile/></code> parameter.
*
* @throws Exception if any
*/
public void testStylesheetfile() throws Exception {
File testPom = new File(unit, "stylesheetfile-test/pom.xml");
JavadocReport mojo = lookupMojo(testPom);
assertNotNull(mojo);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
File apidocs = new File(getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs");
File stylesheetfile = new File(apidocs, "stylesheet.css");
File options = new File(apidocs, "options");
// stylesheet == maven OR java
setVariableValueToObject(mojo, "stylesheet", "javamaven");
try {
mojo.execute();
assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}
// stylesheet == java
setVariableValueToObject(mojo, "stylesheet", "java");
mojo.execute();
String content = readFile(stylesheetfile);
assertTrue(content.contains("/* Javadoc style sheet */"));
String optionsContent = readFile(options);
assertFalse(optionsContent.contains("-stylesheetfile"));
// stylesheet == maven
setVariableValueToObject(mojo, "stylesheet", "maven");
mojo.execute();
content = readFile(stylesheetfile);
assertTrue(content.contains("/* Javadoc style sheet */") && content.contains("Licensed to the Apache Software Foundation (ASF) under one"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-stylesheetfile"));
assertTrue(optionsContent.contains("'" + stylesheetfile.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// stylesheetfile defined as a project resource
setVariableValueToObject(mojo, "stylesheet", null);
setVariableValueToObject(mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css");
mojo.execute();
content = readFile(stylesheetfile);
assertTrue(content.contains("/* Custom Javadoc style sheet in project */"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-stylesheetfile"));
File stylesheetResource = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css");
assertTrue(optionsContent.contains("'" + stylesheetResource.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// stylesheetfile defined in a javadoc plugin dependency
setVariableValueToObject(mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css");
mojo.execute();
content = readFile(stylesheetfile);
assertTrue(content.contains("/* Custom Javadoc style sheet in artefact */"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-stylesheetfile"));
assertTrue(optionsContent.contains("'" + stylesheetfile.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// stylesheetfile defined as file
File css = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css");
setVariableValueToObject(mojo, "stylesheetfile", css.getAbsolutePath());
mojo.execute();
content = readFile(stylesheetfile);
assertTrue(content.contains("/* Custom Javadoc style sheet as file */"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-stylesheetfile"));
stylesheetResource = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css");
assertTrue(optionsContent.contains("'" + stylesheetResource.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
}
use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.
the class JavadocReportTest method testHelpfile.
/**
* Method to test the <code><helpfile/></code> parameter.
*
* @throws Exception if any
*/
public void testHelpfile() throws Exception {
File testPom = new File(unit, "helpfile-test/pom.xml");
JavadocReport mojo = lookupMojo(testPom);
assertNotNull(mojo);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
File apidocs = new File(getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs");
File helpfile = new File(apidocs, "help-doc.html");
File options = new File(apidocs, "options");
// helpfile by default
mojo.execute();
String content = readFile(helpfile);
assertTrue(content.contains("<!-- Generated by javadoc"));
String optionsContent = readFile(options);
assertFalse(optionsContent.contains("-helpfile"));
// helpfile defined in a javadoc plugin dependency
setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html");
setVariableValueToObject(mojo, "session", session);
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from artefact -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
File help = new File(apidocs, "help-doc.html");
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// helpfile defined as a project resource
setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html");
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from file -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// helpfile defined as file
help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
setVariableValueToObject(mojo, "helpfile", help.getAbsolutePath());
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from file -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
}
use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.
the class DefaultDependencyResolverTest method newMavenSession.
protected MavenSession newMavenSession(MavenProject project) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
repoSession.setLocalRepositoryManager(LegacyLocalRepositoryManager.wrap(new StubArtifactRepository("target/local-repo"), null));
MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
return session;
}
Aggregations