forked from arquillian/arquillian-spacelift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves issue arquillian#15 by changing zip4j to commons-compress. A…
…lso adds a TarTool.
- Loading branch information
1 parent
66da963
commit 3301929
Showing
10 changed files
with
499 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
spacelift-impl/src/main/java/org/arquillian/spacelift/tool/basic/FilePermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.arquillian.spacelift.tool.basic; | ||
|
||
/** | ||
* File permission | ||
* | ||
* @author <a href="asotobu@gmail.com">Alex Soto</a> | ||
* | ||
*/ | ||
public class FilePermission { | ||
|
||
private boolean ownerCanRead; | ||
private boolean ownerCanWrite; | ||
private boolean ownerCanExecute; | ||
|
||
private boolean groupCanRead; | ||
private boolean groupCanWrite; | ||
private boolean groupCanExecute; | ||
|
||
private boolean othersCanRead; | ||
private boolean othersCanWrite; | ||
private boolean othersCanExecute; | ||
|
||
public boolean isOwnerCanRead() { | ||
return ownerCanRead; | ||
} | ||
|
||
public void setOwnerCanRead(boolean ownerCanRead) { | ||
this.ownerCanRead = ownerCanRead; | ||
} | ||
|
||
public boolean isOwnerCanWrite() { | ||
return ownerCanWrite; | ||
} | ||
|
||
public void setOwnerCanWrite(boolean ownerCanWrite) { | ||
this.ownerCanWrite = ownerCanWrite; | ||
} | ||
|
||
public boolean isOwnerCanExecute() { | ||
return ownerCanExecute; | ||
} | ||
|
||
public void setOwnerCanExecute(boolean ownerCanExecute) { | ||
this.ownerCanExecute = ownerCanExecute; | ||
} | ||
|
||
public boolean isGroupCanRead() { | ||
return groupCanRead; | ||
} | ||
|
||
public void setGroupCanRead(boolean groupCanRead) { | ||
this.groupCanRead = groupCanRead; | ||
} | ||
|
||
public boolean isGroupCanWrite() { | ||
return groupCanWrite; | ||
} | ||
|
||
public void setGroupCanWrite(boolean groupCanWrite) { | ||
this.groupCanWrite = groupCanWrite; | ||
} | ||
|
||
public boolean isGroupCanExecute() { | ||
return groupCanExecute; | ||
} | ||
|
||
public void setGroupCanExecute(boolean groupCanExecute) { | ||
this.groupCanExecute = groupCanExecute; | ||
} | ||
|
||
public boolean isOthersCanRead() { | ||
return othersCanRead; | ||
} | ||
|
||
public void setOthersCanRead(boolean othersCanRead) { | ||
this.othersCanRead = othersCanRead; | ||
} | ||
|
||
public boolean isOthersCanWrite() { | ||
return othersCanWrite; | ||
} | ||
|
||
public void setOthersCanWrite(boolean othersCanWrite) { | ||
this.othersCanWrite = othersCanWrite; | ||
} | ||
|
||
public boolean isOthersCanExecute() { | ||
return othersCanExecute; | ||
} | ||
|
||
public void setOthersCanExecute(boolean othersCanExecute) { | ||
this.othersCanExecute = othersCanExecute; | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
spacelift-impl/src/main/java/org/arquillian/spacelift/tool/basic/PermissionsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.arquillian.spacelift.tool.basic; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* File util | ||
* | ||
* @author <a href="asotobu@gmail.com">Alex Soto</a> | ||
* | ||
*/ | ||
public class PermissionsUtil { | ||
|
||
private static final int OWNER_READ_FLAG = 0400; | ||
private static final int OWNER_WRITE_FLAG = 0200; | ||
private static final int OWNER_EXECUTE_FLAG = 0100; | ||
|
||
private static final int GROUP_READ_FLAG = 0040; | ||
private static final int GROUP_WRITE_FLAG = 0020; | ||
private static final int GROUP_EXECUTE_FLAG = 0010; | ||
|
||
private static final int OTHERS_READ_FLAG = 0004; | ||
private static final int OTHERS_WRITE_FLAG = 0002; | ||
private static final int OTHERS_EXECUTE_FLAG = 0001; | ||
|
||
public static FilePermission toFilePermission(int mode) { | ||
|
||
int maskedMode = mode & 0777; | ||
FilePermission filePermission = new FilePermission(); | ||
|
||
if ((maskedMode & OWNER_READ_FLAG) > 0) | ||
filePermission.setOwnerCanRead(true); | ||
if ((maskedMode & OWNER_WRITE_FLAG) > 0) | ||
filePermission.setOwnerCanWrite(true); | ||
if ((maskedMode & OWNER_EXECUTE_FLAG) > 0) | ||
filePermission.setOwnerCanExecute(true); | ||
|
||
if ((maskedMode & GROUP_READ_FLAG) > 0) | ||
filePermission.setGroupCanRead(true); | ||
if ((maskedMode & GROUP_WRITE_FLAG) > 0) | ||
filePermission.setGroupCanWrite(true); | ||
if ((maskedMode & GROUP_EXECUTE_FLAG) > 0) | ||
filePermission.setGroupCanExecute(true); | ||
|
||
if ((maskedMode & OTHERS_READ_FLAG) > 0) | ||
filePermission.setOthersCanRead(true); | ||
if ((maskedMode & OTHERS_WRITE_FLAG) > 0) | ||
filePermission.setOthersCanWrite(true); | ||
if ((maskedMode & OTHERS_EXECUTE_FLAG) > 0) | ||
filePermission.setOthersCanExecute(true); | ||
|
||
return filePermission; | ||
|
||
} | ||
|
||
public static void applyPermission(File file, FilePermission permissions) { | ||
|
||
setExecutable(file, permissions.isOwnerCanExecute(), | ||
!permissions.isGroupCanExecute() && !permissions.isOthersCanExecute()); | ||
setWritable(file, permissions.isOwnerCanWrite(), | ||
!permissions.isGroupCanWrite() && !permissions.isOthersCanWrite()); | ||
setReadable(file, permissions.isOwnerCanRead(), !permissions.isGroupCanRead() && !permissions.isOthersCanRead()); | ||
|
||
} | ||
|
||
private static void setReadable(File file, boolean ownerCanRead, boolean group) { | ||
file.setReadable(ownerCanRead, group); | ||
} | ||
|
||
private static void setWritable(File file, boolean ownerCanWrite, boolean group) { | ||
file.setWritable(ownerCanWrite, group); | ||
} | ||
|
||
private static void setExecutable(File file, boolean ownerCanExecute, boolean group) { | ||
file.setExecutable(ownerCanExecute, group); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
spacelift-impl/src/main/java/org/arquillian/spacelift/tool/basic/UncompressTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.arquillian.spacelift.tool.basic; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
|
||
import org.apache.commons.compress.archivers.ArchiveEntry; | ||
import org.apache.commons.compress.archivers.ArchiveInputStream; | ||
import org.arquillian.spacelift.tool.Tool; | ||
|
||
/** | ||
* Uncompress Tool | ||
* | ||
* @author <a href="asotobu@gmail.com">Alex Soto</a> | ||
* | ||
*/ | ||
public abstract class UncompressTool extends Tool<File, File> { | ||
|
||
private static final int BUFFER = 2048; | ||
|
||
private File dest; | ||
|
||
protected abstract ArchiveInputStream compressedInputStream(InputStream compressedFile); | ||
|
||
protected abstract int permissionsMode(ArchiveEntry archiveEntry); | ||
|
||
/** | ||
* | ||
* @param pathToDestination | ||
* destination where to unzip a file | ||
* @return | ||
*/ | ||
public UncompressTool toDir(String pathToDestination) { | ||
return toDir(new File(pathToDestination)); | ||
} | ||
|
||
/** | ||
* | ||
* @param destination | ||
* destination where to unzip a file | ||
* @return | ||
*/ | ||
public UncompressTool toDir(File destination) { | ||
this.dest = destination; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected File process(File input) throws Exception { | ||
ArchiveEntry entry = null; | ||
|
||
/** Read the tar entries using the getNextEntry method **/ | ||
|
||
ArchiveInputStream compressedInputStream = compressedInputStream(new FileInputStream(input)); | ||
|
||
while ((entry = compressedInputStream.getNextEntry()) != null) { | ||
|
||
File file = new File(this.dest, entry.getName()); | ||
|
||
if (entry.isDirectory()) { | ||
File f = file; | ||
f.mkdirs(); | ||
} else { | ||
|
||
if (!file.getParentFile().exists()) { | ||
file.getParentFile().mkdirs(); | ||
} | ||
|
||
int count; | ||
byte data[] = new byte[BUFFER]; | ||
|
||
FileOutputStream fos = new FileOutputStream(file); | ||
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); | ||
while ((count = compressedInputStream.read(data, 0, BUFFER)) != -1) { | ||
dest.write(data, 0, count); | ||
} | ||
dest.close(); | ||
|
||
int permissionsMode = permissionsMode(entry); | ||
if (permissionsMode != 0) { | ||
FilePermission filePermission = PermissionsUtil.toFilePermission(permissionsMode); | ||
PermissionsUtil.applyPermission(file, filePermission); | ||
} | ||
} | ||
} | ||
|
||
compressedInputStream.close(); | ||
|
||
return this.dest; | ||
} | ||
|
||
} |
Oops, something went wrong.