本文整理汇总了Java中org.fuin.utils4j.Utils4J类的典型用法代码示例。如果您正苦于以下问题:Java Utils4J类的具体用法?Java Utils4J怎么用?Java Utils4J使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Utils4J类属于org.fuin.utils4j包,在下文中一共展示了Utils4J类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testwriteInitialLogbackXml
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Test
public void testwriteInitialLogbackXml() throws IOException {
// PREPARE
final File logbackXmlFile = File
.createTempFile(this.getClass().getSimpleName() + "-testwriteInitialLogbackXml-", ".xml");
// TEST
LogbackStandalone.writeInitialLogbackXml(logbackXmlFile, Level.WARN,
this.getClass().getPackage().getName(), Level.INFO,
"%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", "ext4logback-2");
// VERIFY
final String expectedXml = IOUtils.toString(Utils4J.url("classpath:logback-expected-2.xml"),
Charset.forName("utf-8"));
assertThat(logbackXmlFile).hasContent(expectedXml);
}
示例2: validate
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
private static void validate(final Model model) {
final List<Dependency> dependencies = model.getDependencies();
for (final Dependency dependency : dependencies) {
if (dependency.getVersion() == null) {
final DependencyManagement dm = model.getDependencyManagement();
final String version = findVersion(dm, dependency);
if (version == null) {
throw new IllegalStateException(
"Dependency version not set for '"
+ dependency.getGroupId() + ":"
+ dependency.getArtifactId() + "' in '"
+ model.getGroupId() + ":"
+ model.getArtifactId() + ":"
+ model.getVersion() + "'");
}
dependency.setVersion(Utils4J.replaceVars(version,
createVarMap(model)));
}
}
}
示例3: readAtomFeed
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Override
public final List<URI> readAtomFeed(final InputStream in) {
final Document doc = parseDocument(createDocumentBuilder(), in);
final XPath xPath = createXPath("ns", "http://www.w3.org/2005/Atom");
final NodeList nodeList = findNodes(doc, xPath, "/ns:feed/ns:entry/ns:id");
final List<URI> uris = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++) {
final Node node = nodeList.item(i);
final String text = node.getTextContent();
try {
uris.add(Utils4J.url(text).toURI());
} catch (final URISyntaxException ex) {
throw new RuntimeException("Couldn't create URI: " + text);
}
}
return uris;
}
示例4: readAtomFeed
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Override
public final List<URI> readAtomFeed(final InputStream in) {
final List<URI> uris = new ArrayList<>();
final JsonReader jsonReader = Json.createReader(new InputStreamReader(in));
final JsonObject jsonObj = jsonReader.readObject();
final JSONArray read = JsonPath.read(jsonObj, "$.entries..id");
if (read != null) {
for (int i = 0; i < read.size(); i++) {
final JsonString id = (JsonString) read.get(i);
final String uri = id.getString();
try {
uris.add(Utils4J.url(uri).toURI());
} catch (final URISyntaxException ex) {
throw new RuntimeException("Couldn't create URI: " + uri);
}
}
}
return uris;
}
示例5: downloadEventStoreArchive
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
private File downloadEventStoreArchive() throws MojoExecutionException {
final URL url = createDownloadURL();
try {
final File file = getDownloadFile();
if (file.exists()) {
LOG.info("Archive already exists in target directory: " + file);
} else {
LOG.info("Dowloading archive: " + url);
// Cache the file locally in the temporary directory
final File tmpFile = new File(Utils4J.getTempDir(), file.getName());
if (!tmpFile.exists()) {
download(url, tmpFile);
LOG.info("Archive downloaded to: " + tmpFile);
}
FileUtils.copyFile(tmpFile, file);
LOG.info("Archive copied from '" + tmpFile + "' to:" + file);
}
return file;
} catch (final IOException ex) {
throw new MojoExecutionException("Error downloading event store archive: " + url, ex);
}
}
示例6: testUnTarGz
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Test
public void testUnTarGz() throws MojoExecutionException, IOException {
// PREPARE
final String name = this.getClass().getSimpleName() + "-testUnTarGz";
final File archive = File.createTempFile(name + "-", ".tar.gz");
final File destDir = new File(Utils4J.getTempDir(), name);
init("example.tar.gz", archive, destDir);
// TEST
EventStoreDownloadMojo.unTarGz(archive, destDir);
// VERIFY
assertAllExists(destDir);
}
示例7: testUnTarGzFilesOnly
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Test
public void testUnTarGzFilesOnly() throws MojoExecutionException, IOException {
// PREPARE
final String name = this.getClass().getSimpleName() + "-testUnTarGzFilesOnly";
final File archive = File.createTempFile(name + "-", ".tar.gz");
final File destDir = new File(Utils4J.getTempDir(), name);
init("files-only.tar.gz", archive, destDir);
// TEST
EventStoreDownloadMojo.unTarGz(archive, destDir);
// VERIFY
assertAllExists(destDir);
}
示例8: testUnzip
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Test
public void testUnzip() throws MojoExecutionException, IOException {
// PREPARE
final String name = this.getClass().getSimpleName() + "-testUnzip";
final File archive = File.createTempFile(name + "-", ".zip");
final File destDir = new File(Utils4J.getTempDir(), name);
init("example.zip", archive, destDir);
// TEST
EventStoreDownloadMojo.unzip(archive, destDir);
// VERIFY
assertAllExists(destDir);
}
示例9: testDownload
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Test
public void testDownload() throws IOException {
// PREPARE
final URL versionURL = new URL(AbstractEventStoreMojo.VERSION_URL);
final Downloads testee = new Downloads(versionURL,
new File(Utils4J.getTempDir(),
"event-store-versions-" + UUID.randomUUID() + ".json"));
// TEST
testee.parse();
// VERIFY
assertThat(testee.getOsList()).containsExactlyInAnyOrder(
new DownloadOS("ubuntu-16.04"), new DownloadOS("ubuntu-14.04"),
new DownloadOS("osx-10.10"), new DownloadOS("win"));
final DownloadOS ubuntu = testee.findOS("ubuntu-16.04");
assertThat(ubuntu.getOS()).isEqualTo("ubuntu-16.04");
assertThat(ubuntu.getCurrentVersion()).isNotNull();
}
示例10: parseDir
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
/**
* Parse the directory and it's sub directory.
*
* @param dir
* Directory to parse.
*/
private void parseDir(final File dir) {
LOG.debug("Parse: " + dir);
final File[] files = getFiles(dir);
if ((files == null) || (files.length == 0)) {
LOG.debug("No files found in directory: " + dir);
} else {
for (final File file : files) {
if (file.isFile()) {
final Resource resource = resourceSet.getResource(
URI.createFileURI(Utils4J.getCanonicalPath(file)),
true);
LOG.debug("Parsed: " + resource.getURI());
} else {
parseDir(file);
}
}
}
}
示例11: createAndInit
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
/**
* Creates and initializes a SrcGen4J configuration from a configuration
* file that contains ONLY generators/parsers of type
* {@link ParameterizedTemplateParser} and
* {@link ParameterizedTemplateGenerator}.
*
* @param context
* Current context - Cannot be NULL.
* @param configFile
* XML configuration file to read - Cannot be NULL.
*
* @return New configuration instance.
*
* @throws UnmarshalObjectException
* Error reading the configuration.
*/
public static SrcGen4JConfig createAndInit(final SrcGen4JContext context,
final File configFile) throws UnmarshalObjectException {
try {
final JaxbHelper helper = new JaxbHelper();
final SrcGen4JConfig config = helper.create(configFile, JAXBContext
.newInstance(SrcGen4JConfig.class,
VelocityGeneratorConfig.class,
ParameterizedTemplateParserConfig.class,
ParameterizedTemplateGeneratorConfig.class));
config.init(context,
Utils4J.getCanonicalFile(configFile.getParentFile()));
return config;
} catch (final JAXBException ex) {
throw new UnmarshalObjectException(
"Error reading the configuration: " + configFile, ex);
}
}
示例12: init
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
/**
* Initializes the model.
*
* @param context
* Current context.
* @param vars
* Variables to use.
*/
public final void init(final SrcGen4JContext context,
final Map<String, String> vars) {
if (template != null) {
template = Utils4J.replaceVars(template, vars);
}
if (arguments != null) {
for (final Argument argument : arguments) {
argument.init(vars);
}
}
if (targetFiles != null) {
for (final TargetFile targetFile : targetFiles) {
targetFile.init(vars);
}
}
if (tflProducerConfig != null) {
tflProducerConfig.init(context, this, vars);
}
}
示例13: create
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Override
public final GeneratedArtifact create(@NotNull final Greeting greeting,
@NotNull final Map<String, Object> context,
final boolean preparationRun) throws GenerateException {
try {
final String src = FileUtils.readFileToString(new File(
"src/test/resources/AbstractHello.template"));
final Map<String, String> vars = new HashMap<>();
vars.put("name", greeting.getName());
final String pkg = varMap.get("package");
final String path = pkg.replace('.', '/');
vars.put("package", pkg);
return new GeneratedArtifact(artifact, path + "/AbstractHello"
+ greeting.getName() + ".java", Utils4J.replaceVars(src,
vars).getBytes());
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
}
示例14: create
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@Override
public final GeneratedArtifact create(@NotNull final Greeting greeting,
@NotNull final Map<String, Object> context,
final boolean preparationRun) throws GenerateException {
try {
final String src = FileUtils.readFileToString(new File(
"src/test/resources/Hello.template"));
final Map<String, String> vars = new HashMap<>();
vars.put("name", greeting.getName());
return new GeneratedArtifact(artifact, "a/b/c/Hello"
+ greeting.getName() + ".java", Utils4J.replaceVars(src,
vars).getBytes());
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
}
示例15: beforeClass
import org.fuin.utils4j.Utils4J; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws IOException {
testDir = getTestDir(HiddenFileFilterTest.class.getName());
testDir.mkdir();
visibleFile = new File(testDir, "visible.txt");
FileUtils.touch(visibleFile);
visibleFileInfo = createFSI(visibleFile);
hiddenFile = new File(testDir, "hidden.txt");
// TODO xxx In Java 6 there is no way to hide a file
// hiddenFile.setVisible(false);
hiddenFileInfo = createFSI(hiddenFile);
notExistingFile = new File(testDir, "not-existing-file.txt");
notExistingFileInfo = createFSI(notExistingFile);
// Zip the test directory
zipFile = new File(getTempDir(), HiddenFileFilterTest.class.getName() + ".zip");
Utils4J.zipDir(testDir, "", zipFile);
zipFileObj = getZipFileObject(zipFile);
}