Java Code Examples for org.codehaus.plexus.util.ReflectionUtils#setVariableValueInObject()

The following examples show how to use org.codehaus.plexus.util.ReflectionUtils#setVariableValueInObject() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void assemblyFiles(@Injectable final MojoParameters mojoParams,
                          @Injectable final MavenProject project,
                          @Injectable final Assembly assembly) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, MojoExecutionException, AssemblyReadException, IllegalAccessException {

    ReflectionUtils.setVariableValueInObject(assemblyManager, "trackArchiver", trackArchiver);

    new Expectations() {{
        mojoParams.getOutputDirectory();
        result = "target/"; times = 3;

        mojoParams.getProject();
        project.getBasedir();
        result = ".";

        assemblyReader.readAssemblies((AssemblerConfigurationSource) any);
        result = Arrays.asList(assembly);

    }};

    BuildImageConfiguration buildConfig = createBuildConfig();

    assemblyManager.getAssemblyFiles("testImage", buildConfig, mojoParams, new AnsiLogger(new SystemStreamLog(),true,"build"));
}
 
Example 2
Source Project: flow   File: PrepareFrontendMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void jarPackaging_copyProjectFrontendResources()
        throws MojoExecutionException, MojoFailureException,
        IllegalAccessException {
    Mockito.when(project.getPackaging()).thenReturn("jar");

    ReflectionUtils.setVariableValueInObject(mojo, "project", project);

    mojo.execute();

    Mockito.verify(project, Mockito.atLeastOnce()).getArtifacts();
}
 
Example 3
Source Project: flow   File: BuildFrontendMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
static void setProject(AbstractMojo mojo, File baseFolder)
        throws Exception {
    Build buildMock = mock(Build.class);
    when(buildMock.getFinalName()).thenReturn("finalName");
    MavenProject project = mock(MavenProject.class);
    when(project.getBasedir()).thenReturn(baseFolder);
    when(project.getBuild()).thenReturn(buildMock);
    when(project.getRuntimeClasspathElements()).thenReturn(getClassPath());
    ReflectionUtils.setVariableValueInObject(mojo, "project", project);
}
 
Example 4
Source Project: flow   File: BuildFrontendMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void mavenGoal_notGenerateOpenApiJson_when_usingDeprecatedV14Bootstrapping()
        throws Exception {
    ReflectionUtils.setVariableValueInObject(mojo,
            "useDeprecatedV14Bootstrapping", "true");
    Assert.assertFalse(FileUtils.fileExists(openApiJsonFile));
    mojo.execute();
    Assert.assertFalse(FileUtils.fileExists(openApiJsonFile));
}
 
Example 5
@Before
public void setUp() throws Exception {
    resolver = new ImageConfigResolver();
    ReflectionUtils.setVariableValueInObject(resolver, "propertyConfigHandler", new TestHandler(3));
    resolver.initialize();
    resolver.setLog(log);
}
 
Example 6
Source Project: deadcode4j   File: An_UpdateChecker.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    objectUnderTest = new UpdateChecker();
    repositoryMetadataManager = mock(RepositoryMetadataManager.class);
    mavenSession = mock(MavenSession.class);
    when(mavenSession.getCurrentProject()).thenReturn(new MavenProject());
    LegacySupport legacySupport = mock(LegacySupport.class);
    when(legacySupport.getSession()).thenReturn(mavenSession);
    ReflectionUtils.setVariableValueInObject(objectUnderTest, "legacySupport", legacySupport);
    ReflectionUtils.setVariableValueInObject(objectUnderTest, "repositoryMetadataManager",
            repositoryMetadataManager);
}
 
Example 7
@Test
public void issuesWarningForDuplicatedTypeDef() throws IllegalAccessException {
    Logger loggerMock = mock(Logger.class);
    ReflectionUtils.setVariableValueInObject(objectUnderTest, "logger", loggerMock);

    analyzeFile("de/is24/deadcode4j/analyzer/hibernateannotations/ClassWithTypeDef.class");
    analyzeFile("de/is24/deadcode4j/analyzer/hibernateannotations/ClassWithDuplicatedTypeDef.class");
    finishAnalysis();

    verify(loggerMock).warn(
            org.mockito.Matchers.contains("@TypeDef"),
            (Object[]) argThat(hasVarArgItem(equalTo("aRandomType"))));
}
 
Example 8
Source Project: flow   File: PrepareFrontendMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {

    projectBase = temporaryFolder.getRoot();

    tokenFile = new File(temporaryFolder.getRoot(),
            VAADIN_SERVLET_RESOURCES + TOKEN_FILE);

    project = Mockito.mock(MavenProject.class);
    Mockito.when(project.getBasedir()).thenReturn(projectBase);

    flowResourcesFolder = new File(projectBase, DEAULT_FLOW_RESOURCES_FOLDER);
    webpackConfig = new File(projectBase, WEBPACK_CONFIG).getAbsolutePath();
    packageJson = new File(projectBase, PACKAGE_JSON).getAbsolutePath();
    webpackOutputDirectory = new File(projectBase,
            VAADIN_SERVLET_RESOURCES);
    defaultJavaSource = new File(".", "src/test/java");
    generatedTsFolder = new File(projectBase, "frontend/generated");

    ReflectionUtils.setVariableValueInObject(mojo, Constants.NPM_TOKEN,
            projectBase);
    ReflectionUtils.setVariableValueInObject(mojo, "webpackTemplate",
            WEBPACK_CONFIG);
    ReflectionUtils.setVariableValueInObject(mojo,
            "webpackGeneratedTemplate", WEBPACK_GENERATED);
    ReflectionUtils.setVariableValueInObject(mojo,
            Constants.GENERATED_TOKEN, projectBase);
    ReflectionUtils.setVariableValueInObject(mojo, "webpackOutputDirectory",
            webpackOutputDirectory);
    ReflectionUtils.setVariableValueInObject(mojo, "frontendDirectory",
            new File(projectBase, "frontend"));

    ReflectionUtils.setVariableValueInObject(mojo, "openApiJsonFile",
            new File(projectBase,
                    "target/generated-resources/openapi.json"));
    ReflectionUtils.setVariableValueInObject(mojo, "applicationProperties",
            new File(projectBase,
                    "src/main/resources/application.properties"));
    ReflectionUtils.setVariableValueInObject(mojo, "javaSourceFolder",
            defaultJavaSource);
    ReflectionUtils.setVariableValueInObject(mojo, "generatedTsFolder",
            generatedTsFolder);

    ReflectionUtils.setVariableValueInObject(mojo, "pnpmEnable", true);
    ReflectionUtils.setVariableValueInObject(mojo, "requireHomeNodeExec",
            true);
    ReflectionUtils.setVariableValueInObject(mojo, "nodeVersion",
            FrontendTools.DEFAULT_NODE_VERSION);
    ReflectionUtils.setVariableValueInObject(mojo, "nodeDownloadRoot",
            NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT);

    Assert.assertTrue(flowResourcesFolder.mkdirs());
    setProject(mojo, projectBase);
}
 
Example 9
Source Project: flow   File: BuildFrontendMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    MavenProject project = Mockito.mock(MavenProject.class);
    Mockito.when(project.getRuntimeClasspathElements())
            .thenReturn(getClassPath());

    tokenFile = new File(temporaryFolder.getRoot(),
            VAADIN_SERVLET_RESOURCES + TOKEN_FILE);

    File npmFolder = temporaryFolder.getRoot();
    generatedFolder = new File(npmFolder, DEFAULT_GENERATED_DIR);
    importsFile = new File(generatedFolder, IMPORTS_NAME);
    nodeModulesPath = new File(npmFolder, NODE_MODULES);
    flowResourcesFolder = new File(npmFolder, DEAULT_FLOW_RESOURCES_FOLDER);
    File frontendDirectory = new File(npmFolder, DEFAULT_FRONTEND_DIR);

    packageJson = new File(npmFolder, PACKAGE_JSON).getAbsolutePath();
    webpackConfig = new File(npmFolder, WEBPACK_CONFIG).getAbsolutePath();

    projectFrontendResourcesDirectory = new File(npmFolder,
            "flow_resources");

    defaultJavaSource = new File(".", "src/test/java");
    openApiJsonFile = new File(npmFolder,
            "target/generated-resources/openapi.json").getAbsolutePath();
    generatedTsFolder = new File(npmFolder, "frontend/generated");

    Assert.assertTrue("Failed to create a test project resources",
            projectFrontendResourcesDirectory.mkdirs());
    Assert.assertTrue("Failed to create a test project file",
            new File(projectFrontendResourcesDirectory,
                    TEST_PROJECT_RESOURCE_JS).createNewFile());

    ReflectionUtils.setVariableValueInObject(mojo,
            "frontendResourcesDirectory",
            projectFrontendResourcesDirectory);

    ReflectionUtils.setVariableValueInObject(mojo, "project", project);
    ReflectionUtils.setVariableValueInObject(mojo, "generatedFolder",
            generatedFolder);
    ReflectionUtils.setVariableValueInObject(mojo, "frontendDirectory",
            frontendDirectory);
    ReflectionUtils.setVariableValueInObject(mojo,
            "generateEmbeddableWebComponents", false);
    ReflectionUtils.setVariableValueInObject(mojo, "npmFolder", npmFolder);
    ReflectionUtils.setVariableValueInObject(mojo, "generateBundle", false);
    ReflectionUtils.setVariableValueInObject(mojo, "runNpmInstall", false);
    ReflectionUtils.setVariableValueInObject(mojo, "optimizeBundle", true);

    ReflectionUtils.setVariableValueInObject(mojo, "openApiJsonFile",
            new File(npmFolder, "target/generated-resources/openapi.json"));
    ReflectionUtils.setVariableValueInObject(mojo, "applicationProperties",
            new File(npmFolder,
                    "src/main/resources/application.properties"));
    ReflectionUtils.setVariableValueInObject(mojo, "javaSourceFolder",
            defaultJavaSource);
    ReflectionUtils.setVariableValueInObject(mojo, "generatedTsFolder",
            generatedTsFolder);
    ReflectionUtils.setVariableValueInObject(mojo, "nodeVersion",
            FrontendTools.DEFAULT_NODE_VERSION);
    ReflectionUtils.setVariableValueInObject(mojo, "nodeDownloadRoot",
            NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT);

    flowResourcesFolder.mkdirs();
    generatedFolder.mkdirs();

    setProject(mojo, npmFolder);

    // Install all imports used in the tests on node_modules so as we don't
    // need to run `npm install`
    createExpectedImports(frontendDirectory, nodeModulesPath);
    FileUtils.fileWrite(packageJson, "UTF-8",
            TestUtils.getInitalPackageJson().toJson());
}
 
Example 10
Source Project: flow   File: BuildFrontendMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void existingTokenFile_enableDevServerShouldBeAdded()
        throws IOException, IllegalAccessException, MojoExecutionException,
        MojoFailureException {

    File projectBase = temporaryFolder.getRoot();
    File webpackOutputDirectory = new File(projectBase,
            VAADIN_SERVLET_RESOURCES);

    ReflectionUtils.setVariableValueInObject(mojo, "generatedFolder",
            projectBase);
    ReflectionUtils.setVariableValueInObject(mojo, "webpackOutputDirectory",
            webpackOutputDirectory);

    JsonObject initialBuildInfo = Json.createObject();
    initialBuildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, false);
    initialBuildInfo.put(Constants.NPM_TOKEN, "npm");
    initialBuildInfo.put(Constants.GENERATED_TOKEN, "generated");
    initialBuildInfo.put(Constants.FRONTEND_TOKEN, "frontend");

    initialBuildInfo.put(Constants.SERVLET_PARAMETER_ENABLE_PNPM, true);
    initialBuildInfo.put(Constants.REQUIRE_HOME_NODE_EXECUTABLE, true);
    initialBuildInfo
            .put(Constants.SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE, true);

    org.apache.commons.io.FileUtils.forceMkdir(tokenFile.getParentFile());
    org.apache.commons.io.FileUtils.write(tokenFile,
            JsonUtil.stringify(initialBuildInfo, 2) + "\n", "UTF-8");

    mojo.execute();

    String json = org.apache.commons.io.FileUtils
            .readFileToString(tokenFile, "UTF-8");
    JsonObject buildInfo = JsonUtil.parse(json);
    Assert.assertNotNull("devMode token should be available",
            buildInfo.get(SERVLET_PARAMETER_ENABLE_DEV_SERVER));
    Assert.assertNotNull("productionMode token should be available",
            buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));
    Assert.assertNull("npmFolder should have been removed",
            buildInfo.get(Constants.NPM_TOKEN));
    Assert.assertNull("generatedFolder should have been removed",
            buildInfo.get(Constants.GENERATED_TOKEN));
    Assert.assertNull("frontendFolder should have been removed",
            buildInfo.get(Constants.FRONTEND_TOKEN));

    Assert.assertNull(
            Constants.SERVLET_PARAMETER_ENABLE_PNPM
                    + "should have been removed",
            buildInfo.get(Constants.SERVLET_PARAMETER_ENABLE_PNPM));
    Assert.assertNull(
            Constants.REQUIRE_HOME_NODE_EXECUTABLE
                    + "should have been removed",
            buildInfo.get(Constants.REQUIRE_HOME_NODE_EXECUTABLE));
    Assert.assertNull(
            Constants.SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE
                    + "should have been removed",
            buildInfo.get(
                    Constants.SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE));
}