當前位置: 首頁>>代碼示例>>Java>>正文


Java TempFileManager類代碼示例

本文整理匯總了Java中org.wildfly.swarm.bootstrap.util.TempFileManager的典型用法代碼示例。如果您正苦於以下問題:Java TempFileManager類的具體用法?Java TempFileManager怎麽用?Java TempFileManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TempFileManager類屬於org.wildfly.swarm.bootstrap.util包,在下文中一共展示了TempFileManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testExplodedFractionMatching

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void testExplodedFractionMatching() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    File dirFile = TempFileManager.INSTANCE.newTempDirectory("fractionusagetest", null);
    archive.as(ExplodedExporter.class).exportExplodedInto(dirFile);

    analyzer.source(dirFile);
    assertThat(analyzer.detectNeededFractions()
                       .stream()
                       .filter(fd -> fd.getArtifactId().equals("jaxrs"))
                       .count())
            .isEqualTo(1);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:17,代碼來源:FractionUsageAnalyzerTest.java

示例2: customize

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Override
public void customize() throws ModuleLoadException, IOException {

    if (!this.keycloakServer.subresources().themes().isEmpty()) {
        return;
    }

    Module module = Module.getBootModuleLoader().loadModule("org.keycloak.keycloak-themes");
    URL resource = module.getExportedResource("keycloak-themes.jar");

    JARArchive themesArtifact = ShrinkWrap.create(JARArchive.class);
    themesArtifact.as(ZipImporter.class).importFrom(resource.openStream());

    File root = TempFileManager.INSTANCE.newTempDirectory("keycloak-themes", ".d");
    File exportedDir = themesArtifact.as(ExplodedExporter.class).exportExplodedInto(root);
    File themeDir = new File(exportedDir, "theme");

    this.keycloakServer.theme("defaults", (theme) -> {
        theme.dir(themeDir.getAbsolutePath());
        theme.staticmaxage(2592000L);
        theme.cachethemes(true);
        theme.cachetemplates(true);
    });

}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:26,代碼來源:KeycloakThemesCustomizer.java

示例3: droolsWar

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Produces
public Archive droolsWar() throws Exception {
    if (System.getProperty("org.drools.server.swarm.web.conf") == null) {
        //Path dir = Files.createTempDirectory("swarm-keycloak-config");
        File dir = TempFileManager.INSTANCE.newTempDirectory("swarm-drools-web-config", ".d");
        System.setProperty("org.drools.server.swarm.conf", dir.getAbsolutePath());
        Files.copy(getClass().getClassLoader().getResourceAsStream("config/web/web.xml"),
                dir.toPath().resolve("web.xml"),
                StandardCopyOption.REPLACE_EXISTING);
        Files.copy(getClass().getClassLoader().getResourceAsStream("config/web/jboss-web.xml"),
                dir.toPath().resolve("jboss-web.xml"),
                StandardCopyOption.REPLACE_EXISTING);
        configFolder = dir.toPath().toString();
    }

    DroolsMessages.MESSAGES.configurationDirectory(configFolder);

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "drools-server.war");
    deployment.addAllDependencies();

    deployment.addAsWebInfResource(new File(configFolder + "/web.xml"), "web.xml");
    deployment.addAsWebInfResource(new File(configFolder + "/jboss-web.xml"), "jboss-web.xml");

    return deployment;
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:26,代碼來源:DroolsDeploymentProducer.java

示例4: downloadFromRemoteRepository

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void downloadFromRemoteRepository() throws IOException {
    //GIVEN
    File dirFile = TempFileManager.INSTANCE.newTempDirectory(".gradle", null);
    Path gradleCachePath = dirFile.toPath();
    String group = "org.wildfly.swarm";
    String packaging = "jar";
    String artifact = "bootstrap";
    String version = "2017.1.1";
    ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version);

    Path artifactDirectory = gradleCachePath.resolve(group);
    GradleResolver resolver = spy(new GradleResolver(gradleCachePath.toString()));
    File targetFile = mock(File.class);
    doReturn(targetFile).when(resolver).doDownload(anyString(), anyString(), anyString(), eq(artifactCoordinates), eq(packaging), any(File.class), any(File.class));

    //WHEN
    File result = resolver.downloadFromRemoteRepository(artifactCoordinates, packaging, artifactDirectory);

    //THEN
    assertEquals(targetFile, result);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:23,代碼來源:GradleResolverTest.java

示例5: downloadFromRemoteRepository_unknown

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void downloadFromRemoteRepository_unknown() throws IOException {
    //GIVEN
    File dirFile = TempFileManager.INSTANCE.newTempDirectory(".gradle", null);
    Path gradleCachePath = dirFile.toPath();
    String group = "org.wildfly.swarm";
    String packaging = "jar";
    String artifact = "test";
    String version = "2017.1.1";
    ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version);

    Path artifactDirectory = gradleCachePath.resolve(group);
    GradleResolver resolver = spy(new GradleResolver(gradleCachePath.toString()));
    doReturn(null).when(resolver).doDownload(anyString(), anyString(), anyString(), eq(artifactCoordinates), eq(packaging), any(File.class), any(File.class));

    //WHEN
    File result = resolver.downloadFromRemoteRepository(artifactCoordinates, packaging, artifactDirectory);

    //THEN
    assertNull(result);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:22,代碼來源:GradleResolverTest.java

示例6: testResolveArtifact

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void testResolveArtifact() throws IOException {
    //GIVEN
    File dirFile = TempFileManager.INSTANCE.newTempDirectory("gradle", null);
    Path gradleCachePath = dirFile.toPath();
    String group = "org.wildfly.swarm";
    String packaging = "jar";
    String artifact = "test";
    String version = "1.0";
    String classifier = "sources";
    ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version, classifier);

    Path artifactDir = Files.createDirectories(gradleCachePath.resolve(group).resolve(artifact).resolve(version).resolve("hash"));
    File artifactFile = Files.createFile(artifactDir.resolve(artifact + "-" + version + "-" + classifier + "." + packaging)).toFile();

    //WHEN
    GradleResolver resolver = new GradleResolver(gradleCachePath.toString());
    File resolvedArtifactFile = resolver.resolveArtifact(artifactCoordinates, packaging);

    //THEN
    assertEquals(artifactFile, resolvedArtifactFile);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:23,代碼來源:GradleResolverTest.java

示例7: testResolveArtifact_latest

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void testResolveArtifact_latest() throws IOException, InterruptedException {
    //GIVEN
    File dirFile = TempFileManager.INSTANCE.newTempDirectory("gradle", null);
    Path gradleCachePath = dirFile.toPath();
    String group = "org.wildfly.swarm";
    String packaging = "jar";
    String artifact = "test";
    String version = "1.0";
    String classifier = "sources";
    ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version, classifier);

    Path artifactDir = Files.createDirectories(gradleCachePath.resolve(group).resolve(artifact).resolve(version).resolve("hash1"));
    File artifactFile = Files.createFile(artifactDir.resolve(artifact + "-" + version + "-" + classifier + "." + packaging)).toFile();
    Thread.sleep(2000); //Timestemp resolution of some filesystems are 2 seconds
    Path artifactDirLatest = Files.createDirectories(gradleCachePath.resolve(group).resolve(artifact).resolve(version).resolve("hash2"));
    File artifactFileLatest = Files.createFile(artifactDirLatest.resolve(artifact + "-" + version + "-" + classifier + "." + packaging)).toFile();

    //WHEN
    GradleResolver resolver = new GradleResolver(gradleCachePath.toString());
    File resolvedArtifactFile = resolver.resolveArtifact(artifactCoordinates, packaging);

    //THEN
    assertEquals(artifactFileLatest, resolvedArtifactFile);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:26,代碼來源:GradleResolverTest.java

示例8: testResolveArtifact_notExists

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void testResolveArtifact_notExists() throws IOException {
    //GIVEN
    File dirFile = TempFileManager.INSTANCE.newTempDirectory("gradle", null);
    Path gradleCachePath = dirFile.toPath();
    String group = "org.wildfly.swarm";
    String packaging = "jar";
    String artifact = "test";
    String version = "1.0";
    String classifier = "sources";
    ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version, classifier);

    Path artifactDir = Files.createDirectories(gradleCachePath.resolve(group).resolve(artifact).resolve(version).resolve("hash"));
    File artifactFile = Files.createFile(artifactDir.resolve(artifact + "-" + version + "-" + classifier + ".pom")).toFile(); // Other packaging type

    //WHEN
    GradleResolver resolver = new GradleResolver(gradleCachePath.toString());
    File resolvedArtifactFile = resolver.resolveArtifact(artifactCoordinates, packaging);

    //THEN
    assertNull(resolvedArtifactFile);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:23,代碼來源:GradleResolverTest.java

示例9: testFractionMatchingExploded

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Test
public void testFractionMatchingExploded() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("META-INF/persistence.xml");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    File dirFile = TempFileManager.INSTANCE.newTempDirectory("jpatest", null);
    archive.as(ExplodedExporter.class).exportExplodedInto(dirFile);

    analyzer.source(dirFile);
    assertThat(analyzer.detectNeededFractions()
                   .stream()
                   .filter(fd -> fd.getArtifactId().equals("jpa"))
                   .count()).isEqualTo(1);
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:16,代碼來源:JPATest.java

示例10: checkDataDir

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
protected void checkDataDir() {
    // Remove when SWARM-634 is fixed
    if (System.getProperty(JBOSS_DATA_DIR) == null) {
        File tmpDir = null;
        try {
            tmpDir = TempFileManager.INSTANCE.newTempDirectory("wildfly-swarm-data", ".d");
            System.setProperty(JBOSS_DATA_DIR, tmpDir.getAbsolutePath());
        } catch (IOException e) {
            // Ignore
        }
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:13,代碼來源:CertInfoProducer.java

示例11: init

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@PostConstruct
void init() {
    File serverTmp;
    try {
        serverTmp = TempFileManager.INSTANCE.newTempDirectory(TEMP_DIR_NAME, ".d");
        System.setProperty("jboss.server.temp.dir", serverTmp.getAbsolutePath());

        ScheduledExecutorService tempFileExecutor = Executors.newSingleThreadScheduledExecutor();
        this.tempFileProvider = TempFileProvider.create(TEMP_DIR_NAME, tempFileExecutor, true);

    } catch (IOException e) {
        SwarmMessages.MESSAGES.errorSettingUpTempFileProvider(e);
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:15,代碼來源:TempFileProviderProducer.java

示例12: addAsset

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
protected void addAsset(ModuleSpec.Builder builder, ApplicationEnvironment env) throws IOException {
    String path = env.getAsset();
    if (path == null) {
        return;
    }

    int slashLoc = path.lastIndexOf('/');
    String name = path;

    if (slashLoc > 0) {
        name = path.substring(slashLoc + 1);
    }

    String ext = ".jar";
    int dotLoc = name.lastIndexOf('.');
    if (dotLoc > 0) {
        ext = name.substring(dotLoc);
        name = name.substring(0, dotLoc);
    }

    File tmp = File.createTempFile(name, ext);

    try (InputStream artifactIn = getClass().getClassLoader().getResourceAsStream(path)) {
        Files.copy(artifactIn, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

    final String jarName = tmp.getName().toString();
    final JarFile jarFile = new JarFile(tmp);

    File tmpDir = TempFileManager.INSTANCE.newTempDirectory(name, ext);

    //Explode jar due to some issues in Windows on stopping (JarFiles cannot be deleted)
    BootstrapUtil.explodeJar(jarFile, tmpDir.getAbsolutePath());

    jarFile.close();
    tmp.delete();

    final ResourceLoader jarLoader = ResourceLoaders.createFileResourceLoader(jarName, tmpDir);
    builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(jarLoader));

    if (".war".equalsIgnoreCase(ext)) {
        final ResourceLoader warLoader = ResourceLoaders.createFileResourceLoader(jarName + "WEBINF",
                                                                                  new File(tmpDir.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "classes"));

        builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(warLoader));
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:48,代碼來源:ApplicationModuleFinder.java

示例13: copyTempJar

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
public static File copyTempJar(String artifactId, InputStream in, String packaging) throws IOException {
    File tmp = TempFileManager.INSTANCE.newTempFile(artifactId, DOT + packaging);
    Files.copy(in, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    return tmp;
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:6,代碼來源:UberJarMavenResolver.java

示例14: explodedJar

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
public static synchronized Path explodedJar(URL base) throws IOException {
    if (!requiresExplosion(base)) {
        return null;
    }
    try (AutoCloseable locateHandle = Performance.accumulate("Exploded JAR locating")) {
        String urlString = base.toExternalForm();
        if (urlString.startsWith("jar:file:")) {
            int endLoc = urlString.indexOf(JAR_SUFFIX);
            if (endLoc > 0) {
                String jarPath = urlString.substring(9, endLoc + 4);
                //if it has spaces or other characters that would be URL encoded we need to decode them
                jarPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());

                File exp = exploded.get(jarPath);
                if (exp == null) {
                    try (AutoCloseable explodingHandle = Performance.accumulate("Exploding JAR")) {
                        exp = TempFileManager.INSTANCE.newTempDirectory("module-jar", ".jar_d");
                        try (JarFile jarFile = new JarFile(jarPath)) {
                            Enumeration<JarEntry> entries = jarFile.entries();
                            while (entries.hasMoreElements()) {
                                JarEntry each = entries.nextElement();
                                if (!each.isDirectory()) {
                                    File out = new File(exp, each.getName());
                                    out.getParentFile().mkdirs();
                                    InputStream in = jarFile.getInputStream(each);
                                    Files.copy(in, out.toPath(), StandardCopyOption.REPLACE_EXISTING);
                                    in.close();
                                }
                            }
                        }
                        exploded.put(jarPath, exp);
                    }
                }

                String remainder = urlString.substring(endLoc + JAR_SUFFIX.length());
                if (remainder.startsWith("/") || remainder.startsWith("\\")) {
                    remainder = remainder.substring(1);
                }

                return exp.toPath().resolve(remainder);
            }
        }

        return null;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:49,代碼來源:NestedJarResourceLoader.java

示例15: postInitialize

import org.wildfly.swarm.bootstrap.util.TempFileManager; //導入依賴的package包/類
@Override
public void postInitialize(Fraction.PostInitContext initContext) {

    if (System.getProperty("jboss.server.config.dir") == null) {
        try {
            //Path dir = Files.createTempDirectory("swarm-keycloak-config");
            File dir = TempFileManager.INSTANCE.newTempDirectory("swarm-keycloak-config", ".d");
            System.setProperty("jboss.server.config.dir", dir.getAbsolutePath());
            Files.copy(getClass().getClassLoader().getResourceAsStream("keycloak-server.json"),
                       dir.toPath().resolve("keycloak-server.json"),
                       StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    InfinispanFraction infinispan = (InfinispanFraction) initContext.fraction("infinispan");

    CacheContainer cache = infinispan.subresources().cacheContainer("keycloak");
    if (cache == null) {
        infinispan.cacheContainer("keycloak", (c) -> c.jndiName("infinispan/Keycloak")
                .localCache("realms")
                .localCache("users")
                .localCache("sessions")
                .localCache("offlineSessions")
                .localCache("loginFailures")
                .localCache("work")
                .localCache("realmVersions", (ca) -> ca.transactionComponent(new TransactionComponent()
                                                                                     .mode(TransactionComponent.Mode.BATCH)
                                                                                     .locking(TransactionComponent.Locking.PESSIMISTIC)))
        );
    }

    DatasourcesFraction datasources = (DatasourcesFraction) initContext.fraction("datasources");

    if (datasources.subresources().dataSource("KeycloakDS") == null) {
        if (datasources.subresources().jdbcDriver("h2") == null) {
            datasources.jdbcDriver("h2", (driver) -> {
                driver.driverModuleName("com.h2database.h2");
                driver.moduleSlot("main");
                driver.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
            });
        }

        datasources.dataSource("KeycloakDS", (ds) -> {
            ds.jndiName("java:jboss/datasources/KeycloakDS");
            ds.useJavaContext(true);
            ds.connectionUrl("jdbc:h2:${wildfly.swarm.keycloak.server.db:./keycloak};AUTO_SERVER=TRUE");
            ds.driverName("h2");
            ds.userName("sa");
            ds.password("sa");
        });
    }
}
 
開發者ID:wildfly-swarm-archive,項目名稱:wildfly-swarm-keycloak,代碼行數:55,代碼來源:KeycloakServerFraction.java


注:本文中的org.wildfly.swarm.bootstrap.util.TempFileManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。