Bas van Schaik 2017-05-03 14:22:49 +01:00 committed by Vlad Mihalcea
parent 2d4600bbc7
commit 72e0d593b9
4 changed files with 97 additions and 87 deletions

View File

@ -145,8 +145,7 @@ public class ExplodedArchiveDescriptor extends AbstractArchiveDescriptor {
}
private void processZippedRoot(File rootFile, ArchiveContext context) {
try {
final JarFile jarFile = new JarFile(rootFile);
try (final JarFile jarFile = new JarFile(rootFile)){
final Enumeration<? extends ZipEntry> entries = jarFile.entries();
while ( entries.hasMoreElements() ) {
final ZipEntry zipEntry = entries.nextElement();

View File

@ -53,97 +53,106 @@ public class JarFileBasedArchiveDescriptor extends AbstractArchiveDescriptor {
return;
}
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
while ( zipEntries.hasMoreElements() ) {
final ZipEntry zipEntry = zipEntries.nextElement();
final String entryName = extractName( zipEntry );
try {
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
while ( zipEntries.hasMoreElements() ) {
final ZipEntry zipEntry = zipEntries.nextElement();
final String entryName = extractName( zipEntry );
if ( getEntryBasePrefix() != null && ! entryName.startsWith( getEntryBasePrefix() ) ) {
continue;
}
if ( zipEntry.isDirectory() ) {
continue;
}
if ( getEntryBasePrefix() != null && ! entryName.startsWith( getEntryBasePrefix() ) ) {
continue;
}
if ( zipEntry.isDirectory() ) {
continue;
}
if ( entryName.equals( getEntryBasePrefix() ) ) {
// exact match, might be a nested jar entry (ie from jar:file:..../foo.ear!/bar.jar)
//
// This algorithm assumes that the zipped file is only the URL root (including entry), not
// just any random entry
try (InputStream is = new BufferedInputStream( jarFile.getInputStream( zipEntry ) )) {
final JarInputStream jarInputStream = new JarInputStream( is );
ZipEntry subZipEntry = jarInputStream.getNextEntry();
while ( subZipEntry != null ) {
if ( ! subZipEntry.isDirectory() ) {
if ( entryName.equals( getEntryBasePrefix() ) ) {
// exact match, might be a nested jar entry (ie from jar:file:..../foo.ear!/bar.jar)
//
// This algorithm assumes that the zipped file is only the URL root (including entry), not
// just any random entry
try ( final InputStream is = new BufferedInputStream( jarFile.getInputStream( zipEntry ) );
final JarInputStream jarInputStream = new JarInputStream( is )) {
ZipEntry subZipEntry = jarInputStream.getNextEntry();
while ( subZipEntry != null ) {
if ( ! subZipEntry.isDirectory() ) {
final String name = extractName( subZipEntry );
final String relativeName = extractRelativeName( subZipEntry );
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( name, jarInputStream );
final String name = extractName( subZipEntry );
final String relativeName = extractRelativeName( subZipEntry );
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( name, jarInputStream );
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
entryHandler.handleEntry( entry, context );
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
entryHandler.handleEntry( entry, context );
}
subZipEntry = jarInputStream.getNextEntry();
}
}
catch (Exception e) {
throw new ArchiveException( "Error accessing JarFile entry [" + zipEntry.getName() + "]", e );
}
}
else {
final String name = extractName( zipEntry );
final String relativeName = extractRelativeName( zipEntry );
final InputStreamAccess inputStreamAccess;
try (InputStream is = jarFile.getInputStream( zipEntry )) {
inputStreamAccess = buildByteBasedInputStreamAccess( name, is );
}
catch (IOException e) {
throw new ArchiveException(
String.format(
"Unable to access stream from jar file [%s] for entry [%s]",
jarFile.getName(),
zipEntry.getName()
)
);
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
subZipEntry = jarInputStream.getNextEntry();
}
}
catch (Exception e) {
throw new ArchiveException( "Error accessing JarFile entry [" + zipEntry.getName() + "]", e );
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
entryHandler.handleEntry( entry, context );
}
}
else {
final String name = extractName( zipEntry );
final String relativeName = extractRelativeName( zipEntry );
final InputStreamAccess inputStreamAccess;
try (InputStream is = jarFile.getInputStream( zipEntry )) {
inputStreamAccess = buildByteBasedInputStreamAccess( name, is );
}
catch (IOException e) {
throw new ArchiveException(
String.format(
"Unable to access stream from jar file [%s] for entry [%s]",
jarFile.getName(),
zipEntry.getName()
)
);
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
entryHandler.handleEntry( entry, context );
}
finally {
try {
jarFile.close();
}
catch ( Exception ignore ) {
}
}
}

View File

@ -50,7 +50,10 @@ public class ExceptionConverterImpl implements ExceptionConverter {
public RuntimeException convertCommitException(RuntimeException e) {
if ( sharedSessionContract.getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
Throwable wrappedException;
if ( e instanceof PersistenceException ) {
if ( e instanceof HibernateException ) {
wrappedException = convert( (HibernateException) e );
}
else if ( e instanceof PersistenceException ) {
Throwable cause = e.getCause() == null ? e : e.getCause();
if ( cause instanceof HibernateException ) {
wrappedException = convert( (HibernateException) cause );
@ -59,9 +62,6 @@ public class ExceptionConverterImpl implements ExceptionConverter {
wrappedException = cause;
}
}
else if ( e instanceof HibernateException ) {
wrappedException = convert( (HibernateException) e );
}
else {
wrappedException = e;
}

View File

@ -215,7 +215,9 @@ public class SchemaUpdateTask extends MatchingTask {
properties.putAll( getProject().getProperties() );
}
else {
properties.load( new FileInputStream( propertiesFile ) );
try (FileInputStream fip = new FileInputStream( propertiesFile )){
properties.load( fip );
}
}
registryBuilder.applySettings( properties );