public static void main(String[] args) throws Exception { Furnace furnace = startFurnace(); try { AddonRegistry addonRegistry = furnace.getAddonRegistry(); ProjectFactory projectFactory = addonRegistry.getServices(ProjectFactory.class).get(); ResourceFactory resourceFactory = addonRegistry.getServices(ResourceFactory.class).get(); // Create a temporary directory as an example File underlyingResource = OperatingSystemUtils.getTempDirectory(); Resource<File> projectDir = resourceFactory.create(underlyingResource); // This could return more than one provider, but since the maven addon is the only one // deployed, this is ok ProjectProvider projectProvider = addonRegistry.getServices(ProjectProvider.class).get(); // Creating WAR project JavaWebProjectType javaWebProjectType = addonRegistry.getServices(JavaWebProjectType.class).get(); Project project = projectFactory.createProject( projectDir, projectProvider, javaWebProjectType.getRequiredFacets()); // Changing metadata MetadataFacet facet = project.getFacet(MetadataFacet.class); facet.setProjectName("my-demo-project"); facet.setProjectVersion("1.0.0-SNAPSHOT"); facet.setTopLevelPackage("com.mycompany.project"); System.out.println("### Project Created in: " + project); } finally { furnace.stop(); } }
@Test @SuppressWarnings("unchecked") public void testResourceTransactionCommit() throws IOException { File tempDir = OperatingSystemUtils.createTempDir(); File file = createTempFile(tempDir, false); ResourceTransaction transaction = resourceFactory.getTransaction(); Assert.assertNotNull(transaction); Assert.assertFalse(transaction.isStarted()); transaction.begin(); Assert.assertTrue(transaction.isStarted()); FileResource<?> fileResource = resourceFactory.create(FileResource.class, file); Assert.assertNotNull(fileResource); fileResource.setContents("Hello World"); transaction.commit(); Assert.assertTrue(fileResource.exists()); Assert.assertEquals("Hello World", fileResource.getContents()); }
@Test(expected = ResourceTransactionException.class) public void testResourceTimeoutInvalidatesTransaction() throws Exception { ResourceTransaction transaction = resourceFactory.getTransaction(); transaction.setTransactionTimeout(2); transaction.begin(); Thread.sleep(3000); transaction.commit(); }
@Test public void testResourceTransactionSucceeds() throws Exception { ResourceTransaction transaction = resourceFactory.getTransaction(); Assert.assertFalse(transaction.isStarted()); transaction.begin(); Assert.assertTrue(transaction.isStarted()); Thread.sleep(1000); transaction.commit(); Assert.assertFalse(transaction.isStarted()); }
@Test @SuppressWarnings("unchecked") public void testResourceChangeSet() throws IOException { File tempDir = OperatingSystemUtils.createTempDir(); File file = createTempFile(tempDir, true); ResourceTransaction transaction = resourceFactory.getTransaction(); Assert.assertNotNull(transaction); Assert.assertFalse(transaction.isStarted()); transaction.begin(); Assert.assertTrue(transaction.isStarted()); FileResource<?> fileResource = resourceFactory.create(FileResource.class, file); Assert.assertNotNull(fileResource); fileResource.setContents("Hello World"); Assert.assertEquals("Hello World", fileResource.getContents()); Collection<ResourceEvent> changeSet = transaction.getChangeSet(); Assert.assertEquals(3, changeSet.size()); Iterator<ResourceEvent> iterator = changeSet.iterator(); // Created the file { ResourceEvent event = iterator.next(); Assert.assertThat(event, is(instanceOf(ResourceCreated.class))); Assert.assertEquals(fileResource, event.getResource()); } { ResourceEvent event = iterator.next(); // Modified the Directory Assert.assertThat(event, is(instanceOf(ResourceModified.class))); Assert.assertThat(event.getResource(), is(instanceOf(DirectoryResource.class))); } { ResourceEvent event = iterator.next(); // Modified the File resource Assert.assertThat(event, is(instanceOf(ResourceModified.class))); Assert.assertEquals(fileResource, event.getResource()); } Assert.assertFalse(file.exists()); Assert.assertTrue(fileResource.exists()); transaction.commit(); Assert.assertTrue(fileResource.exists()); Assert.assertTrue(file.exists()); Assert.assertEquals("Hello World", fileResource.getContents()); }
@Test public void testClasspathTemplateProcessor() throws Exception { URL template = getClass().getResource("template.ftl"); Assert.assertNotNull(template); String expected = "Hello JBoss Forge!"; Resource<?> resource = resourceFactory.create(template); TemplateProcessor processor = templateProcessorFactory.fromTemplate(new FreemarkerTemplate(resource)); String actual = processor.process(Collections.singletonMap("name", "JBoss Forge")); Assert.assertEquals(expected, actual); }
@Test public void testGenerateHiddenAndRequiredProperty() throws Exception { Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, ENTITY_ID_PROP); Resource<URL> templateResource = resourceFactory.create( getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT)); TemplateProcessor processor = processorFactory.fromTemplate(new FreemarkerTemplate(templateResource)); String output = processor.process(root); assertThat(output.trim(), IsEqual.equalTo("")); }
private void configureTargetLocationInput(final UIBuilder builder) { UISelection<Resource<?>> currentSelection = builder.getUIContext().getInitialSelection(); if (!currentSelection.isEmpty()) { Resource<?> resource = currentSelection.get(); if (resource instanceof DirectoryResource) { targetLocation.setDefaultValue((DirectoryResource) resource); } } else { targetLocation.setDefaultValue( resourceFactory.create(DirectoryResource.class, OperatingSystemUtils.getUserHomeDir())); } }
@Test @SuppressWarnings("rawtypes") public void testTemplateProcessor() throws Exception { String template = "Hello ${name}!"; String expected = "Hello JBoss Forge!"; File tempFile = File.createTempFile("template", ".tmp"); tempFile.deleteOnExit(); FileResource resource = resourceFactory.create(tempFile).reify(FileResource.class); resource.setContents(template); TemplateProcessor processor = templateProcessorFactory.fromTemplate(new FreemarkerTemplate(resource)); String actual = processor.process(Collections.singletonMap("name", "JBoss Forge")); Assert.assertEquals(expected, actual); }
public boolean rulesetsNeedUpdate() { Coordinate lastRelease = this.getLatestReleaseOf(RULES_GROUP_ID, RULESETS_ARTIFACT_ID); Path windupRulesDir = getRulesetsDir(); Path coreRulesPomPath = windupRulesDir.resolve( RULESET_CORE_DIRECTORY + "/META-INF/maven/org.jboss.windup.rules/windup-rulesets/pom.xml"); File pomXml = coreRulesPomPath.toFile(); if (!pomXml.exists()) return false; MavenModelResource pom = (MavenModelResource) factory.create(pomXml); SingleVersion installed = new SingleVersion(pom.getCurrentModel().getVersion()); SingleVersion latest = new SingleVersion(lastRelease.getVersion()); final String msg = "Core rulesets: Installed: " + installed + " Latest release: " + latest; log.info(msg); System.out.println(msg); // Print to both to have the info in the log too. return 0 > installed.compareTo(latest); }
@Test public void testGenerateManyToOneProperty() throws Exception { Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, MANY_TO_ONE_PROP); Resource<URL> templateResource = resourceFactory.create( getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT)); TemplateProcessor processor = processorFactory.fromTemplate(new FreemarkerTemplate(templateResource)); String output = processor.process(root); Document html = Jsoup.parseBodyFragment(output); assertThat(output.trim(), not(equalTo(""))); Elements container = html.select("div.form-group"); assertThat(container, notNullValue()); Elements formInputElement = container.select("div.col-sm-10 > select"); assertThat(formInputElement.attr("id"), equalTo("customer")); assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "customer")); }
@Override public DirectoryResource getLocalRepositoryDirectory() { return factory .create(buildManager.getLocalRepositoryDirectory()) .reify(DirectoryResource.class); }
@After public void tearDown() { ResourceTransaction transaction = resourceFactory.getTransaction(); if (transaction.isStarted()) transaction.rollback(); }
@Test(expected = ResourceTransactionException.class) public void testResourceTimeout() { ResourceTransaction transaction = resourceFactory.getTransaction(); transaction.setTransactionTimeout(-100); }