I need to copy specific files that are in JARs into specific directory in WAR, using Gradle.
My code:
war.doFirst {
for(file in classpath) {
FileTree tree = zipTree(file)
FileTree treeResources = tree.matching { include "META-INF/resources/*" }
String folderName = 'destinationFolder'
{
treeResources.each {
File resources -> copy {
from resources
String dest = war.destinationDir.name + "/" + war.archiveName + "/" + folderName
into dest
}
}
}
}
Problem: the "dest" value is incorrect, instead of being in the created WAR file, it is something like "libs/mywar-1.0.war/destinationFolder".
You'll want something like:
war {
into("destinationFolder") {
from { classpath.collect { zipTree(it) } }
include "META-INF/resources/**"
}
}
Related
I want to get some dependency artifact and copy the content into a specific location.
This works well in general, but not for files called e.g. .gitignore.
I found that those are default excludes.
How can i disable those default exclude, by using the Java-Gradle-API in my plugin code?
project.copy( spec -> {
spec.from (project.zipTree(artifact.getFile()));
spec.into( tf.toFile());
//spec.setExcludes(Collections.emptyList()); // does not work
});
Also i tried to the setExcludes in the from/into copyspec.
Frank
I found a solution, but i don't like it, because it modifies the globally visible defaultExcludes:
private static void withoutDefaultExcludes( Runnable r ) {
String[] defaultExcludes = org.apache.tools.ant.DirectoryScanner.getDefaultExcludes();
try {
for( String defaultExclude : defaultExcludes) {
org.apache.tools.ant.DirectoryScanner.removeDefaultExclude(defaultExclude);
}
r.run();
}
finally {
for( String defaultExclude : defaultExcludes) {
org.apache.tools.ant.DirectoryScanner.addDefaultExclude(defaultExclude);
}
}
}
withoutDefaultExcludes( () -> {
project.copy( spec -> {
spec.from (project.zipTree(artifact.getFile()));
spec.into( tf.toFile());
});
});
In the following cookbook chapter 3.3.3:
https://support.intershop.com/kb/index.php/Display/2V8150
There is a configuration for the jvm arguments, which is not working.
I've tried 4 different configs and they all crash my deploy:
tomcat {
instances {
appserver0 {
jvmArgs {
maxHeapSize = 4096
minHeapSize = 2048
additionalJvmArgs = ['\\u0022-XX:MaxPermSize=256m\\u0022']
}
}
}
}
tomcat {
instances {
appserver0 {
jvmArgs {
maxHeapSize = 4096m
minHeapSize = 2048m
additionalJvmArgs = ['\\u0022-XX:MaxPermSize=256m\\u0022']
}
}
}
}
appserver {
instances {
appserver0 {
jvmArgs {
maxHeapSize = 4096
minHeapSize = 2048
additionalJvmArgs = ['\\u0022-XX:MaxPermSize=256m\\u0022']
}
}
}
}
appserver {
instances {
appserver0 {
jvmArgs {
maxHeapSize = 4096m
minHeapSize = 2048m
additionalJvmArgs = ['\\u0022-XX:MaxPermSize=256m\\u0022']
}
}
}
}
Does someone has this configuration setting working?
The problem seems to be the additional JVM arguments. When leaving this out it works.
This will result in the following code snippet.
tomcat {
instances {
appserver0 {
jvmArgs {
minHeapSize = 2048
maxHeapSize = 4096
}
}
}
}
There was a defect in the deployment tools that caused double quotes to be preceded by a backslash character in the resulting file (in this case the process.appserver0.command property value in $IS_HOME/engine/nodemanager/config/nodemanager.properties). Please check the resulting property value in the nodemanager.properties file and the command line logged into the $IS_HOME/log/nodemanager.log and $IS_HOME/log/appserver0.log files.
The option in the $IS_HOME/engine/nodemanager/config/nodemanager.properties file should be surrounded by double quotes or the encoded form \u0022 – otherwise Windows interprets the = character as a separator (surrounding the option with double quotes is not necessary on Linux platforms).
This underlying issue has been fixed with Gradle tools version 2.11.6.
Please note that the support of the XX:MaxPermSize option was removed in JDK 8.0 (the option is ignored and results in a warning message).
I've a dir (with sub dirs) template that is kept as a resource inside a jar file. During run
time I need to extract it (template) to tmp dir change some content and finally publish it as a zipped artifact.
My question is: how to extract this content easily? I was trying getResource() as well as getResourceAsStream()..
Following code works fine here: (Java7)
String s = this.getClass().getResource("").getPath();
if (s.contains("jar!")) {
// we have a jar file
// format: file:/location...jar!...path-in-the-jar
// we only want to have location :)
int excl = s.lastIndexOf("!");
s = s.substring(0, excl);
s = s.substring("file:/".length());
Path workingDirPath = workingDir = Files.createTempDirectory("demo")
try (JarFile jf = new JarFile(s);){
Enumeration<JarEntry> entries = jf.entries();
while (entries.hasMoreElements()) {
JarEntry je = entries.nextElement();
String name = je.getName();
if (je.isDirectory()) {
// directory found
Path dir = workingDirPath.resolve(name);
Files.createDirectory(dir);
} else {
Path file = workingDirPath.resolve(name);
try (InputStream is = jf.getInputStream(je);) {
Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING);
}
}
}
}
} else {
// debug mode: no jar
}
I have following directory structure,
Dir1
|___Dir2
|___Dir3
|___Dir4
|___File1.gz
|___File2.gz
|___File3.gz
The subdirectories are just nested and donot contain any files
I am trying to use the following for recursing through a directory on HDFS.If its a directory I append /* to the path and addInputPath
arg[0] = "path/to/Dir1"; // given at command line
FileStatus fs = new FileStatus();
Path q = new Path(args[0]);
FileInputFormat.addInputPath(job,q);
Path p = new Path(q.toString()+"/*");
fs.setPath(p);
while(fs.isDirectory())
{
fs.setPath(new Path(p.toString()+"/*"));
FileInputFormat.addInputPath(job,fs.getPath());
}
But the code doesnt seem to go in the while loop and I get not a File Exception
Where is the if statement you are referring to?
Anyway, you may have a look at these utility methods which add all files within a directory to a job's input:
Utils:
public static Path[] getRecursivePaths(FileSystem fs, String basePath)
throws IOException, URISyntaxException {
List<Path> result = new ArrayList<Path>();
basePath = fs.getUri() + basePath;
FileStatus[] listStatus = fs.globStatus(new Path(basePath+"/*"));
for (FileStatus fstat : listStatus) {
readSubDirectory(fstat, basePath, fs, result);
}
return (Path[]) result.toArray(new Path[result.size()]);
}
private static void readSubDirectory(FileStatus fileStatus, String basePath,
FileSystem fs, List<Path> paths) throws IOException, URISyntaxException {
if (!fileStatus.isDir()) {
paths.add(fileStatus.getPath());
}
else {
String subPath = fileStatus.getPath().toString();
FileStatus[] listStatus = fs.globStatus(new Path(subPath + "/*"));
if (listStatus.length == 0) {
paths.add(fileStatus.getPath());
}
for (FileStatus fst : listStatus) {
readSubDirectory(fst, subPath, fs, paths);
}
}
}
Use it in your job runner class:
...
Path[] inputPaths = Utils.getRecursivePaths(fs, inputPath);
FileInputFormat.setInputPaths(job, inputPaths);
...
I want to know all the folders name under "Company Home" directory in Alfresco but getting error.
Code -
ItemIterable<QueryResult> results = session.query("SELECT * FROM cmis:folder where IN_TREE('/Company Home')", false);
try {
for (QueryResult result : results) {
folderId = result.getPropertyValueById(PropertyIds.OBJECT_ID);
Folder folder = (Folder) session.getObject(folderId);
System.out.println("Folder Name " + folder.getName());
}
} catch(Exception e) {
e.printStackTrace();
}
Error -
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: 00270668 Request failed 500 /solr/alfresco/cmis?wt=json&fl=DBID%2Cscore&rows=100&df=TEXT&start=0&locale=en_US&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:452)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:570)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:142)
at org.apache.chemistry.opencmis.client.runtime.SessionImpl$3.fetchPage(SessionImpl.java:567)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
at org.apache.chemistry.opencmis.client.runtime.util.CollectionIterator.hasNext(CollectionIterator.java:48)
at main.java.org.apache.chemistry.opencmis.doc.QueryTest.folderName(QueryTest.java:180)
IN_TREE takes the object id, not the the object path. If you provide the id of the "Company Home" folder, this query should work.
Company Home is the root folder, I suggest you use something like the following:
Session session = createSession();
Folder rootFolder = session.getRootFolder();
ItemIterable<CmisObject> children = rootFolder.getChildren();
for (CmisObject child : children) {
System.out.println(child.getName());
}