Skip to content

Commit

Permalink
Fix error catching issues in travis build (#178)
Browse files Browse the repository at this point in the history
* fix error catching issues in travis build

* prefix

* Fixed tests and and checkstyle
  • Loading branch information
matthieun authored and jwpgage committed Jul 17, 2018
1 parent 0f108ce commit b0e83d7
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ script:
- shellcheck pyatlas/*.sh
- set +e
- .travis/build.sh
- .travis/build-pyatlas-gate.sh
- .travis/sonar-gate.sh
- .travis/merge-dev-to-master-gate.sh
- .travis/deploy-gate.sh
- .travis/tag-master-gate.sh
11 changes: 11 additions & 0 deletions .travis/build-pyatlas-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

if [ $TRAVIS_TEST_RESULT -eq 0 ];
then
./gradlew cleanPyatlas buildPyatlas
RETURN_VALUE=$?
if [ "$RETURN_VALUE" != "0" ];
then
exit $RETURN_VALUE
fi
fi
13 changes: 0 additions & 13 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,7 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ];
then
echo "Skip integration tests in pull request builds"
./gradlew clean build -x integrationTest
./gradlew cleanPyatlas buildPyatlas
else
echo "Temporarily skip integration tests in all builds. Too heavy for Travis"
./gradlew clean build -x integrationTest
./gradlew cleanPyatlas buildPyatlas
fi

if [ "$TRAVIS_EVENT_TYPE" = "cron" ];
then
echo "Running sonarqube in a CRON build"
./gradlew sonarqube \
-Dsonar.organization=osmlab \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.junit.reportPaths=build/test-results/test \
-Dsonar.jacoco.reportPaths=build/jacoco/test.exec
fi
11 changes: 11 additions & 0 deletions .travis/sonar-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

if [ $TRAVIS_TEST_RESULT -eq 0 ];
then
.travis/sonar.sh
RETURN_VALUE=$?
if [ "$RETURN_VALUE" != "0" ];
then
exit $RETURN_VALUE
fi
fi
12 changes: 12 additions & 0 deletions .travis/sonar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

if [ "$TRAVIS_EVENT_TYPE" = "cron" ];
then
echo "Running sonarqube in a CRON build"
./gradlew sonarqube \
-Dsonar.organization=osmlab \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.junit.reportPaths=build/test-results/test \
-Dsonar.jacoco.reportPaths=build/jacoco/test.exec
fi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static PolyLine random(final int numberPoints, final Rectangle bounds)
public static void saveAsGeoJson(final Iterable<? extends Iterable<Location>> geometries,
final WritableResource resource)
{
try (final JsonWriter writer = new JsonWriter(resource))
try (JsonWriter writer = new JsonWriter(resource))
{
writer.write(asGeoJson(geometries).jsonObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.function.Supplier;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.openstreetmap.atlas.exception.CoreException;
import org.openstreetmap.atlas.streaming.Streams;
import org.openstreetmap.atlas.streaming.resource.File;
import org.openstreetmap.atlas.streaming.resource.InputStreamResource;
import org.openstreetmap.atlas.streaming.resource.Resource;
Expand All @@ -20,6 +20,22 @@
*/
public class ZipFileWritableResource extends ZipWritableResource
{
private static Supplier<InputStream> inputStreamSupplier(final ZipFile file,
final ZipEntry entry)
{
return () ->
{
try
{
return file.getInputStream(entry);
}
catch (final IOException e)
{
throw new CoreException("Cannot get the entry {}", entry.getName(), e);
}
};
}

public ZipFileWritableResource(final File source)
{
super(source);
Expand All @@ -28,22 +44,20 @@ public ZipFileWritableResource(final File source)
@Override
public Iterable<Resource> entries()
{
try (final ZipFile file = new ZipFile(getFileSource().getFile()))
try (ZipFile file = new ZipFile(getFileSource().getFile())
{
@Override
public void close()
{
// Do nothing to close the file here, to avoid cutting the legs off the just created
// ZipEntry-based resource.
}
})
{
final ZipFile fileCopy = file;
return Iterables.translate(Iterables.from(file.entries()), entry ->
{
try
{
final InputStream input = fileCopy.getInputStream(entry);
return new InputStreamResource(input).withName(entry.getName());
}
catch (final IOException e)
{
Streams.close(fileCopy);
throw new CoreException("Cannot get the entry {} from the Zipfile {}.",
entry.getName(), this.getFileSource().getName(), e);
}
return new InputStreamResource(inputStreamSupplier(file, entry))
.withName(entry.getName());
});
}
catch (final IOException e)
Expand All @@ -63,17 +77,23 @@ public Iterable<Resource> entries()
*/
public Resource entryForName(final String name)
{
try (final ZipFile file = new ZipFile(getFileSource().getFile()))
try (ZipFile file = new ZipFile(getFileSource().getFile())
{
@Override
public void close()
{
// Do nothing to close the file here, to avoid cutting the legs off the just created
// ZipEntry-based resource.
}
})
{
final ZipEntry entry = file.getEntry(name);
if (entry != null)
{
final InputStream input = file.getInputStream(entry);
return new InputStreamResource(input).withName(name);
return new InputStreamResource(inputStreamSupplier(file, entry)).withName(name);
}
else
{
Streams.close(file);
throw new IOException("Entry " + name + " does not exist.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public Extractor extract(final File inputFile) throws ArchiveException, IOExcept
}

fireArchiveStarted();
try (final ZipFile file = new ZipFile(inputFile))
try (ZipFile file = new ZipFile(inputFile))
{
for (final ZipArchiveEntry current : Collections.list(file.getEntries()))
{
Expand All @@ -201,9 +201,9 @@ else if (current.isDirectory())
}
else
{
try (final BufferedOutputStream bos = new BufferedOutputStream(
try (BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(outputFile));
final InputStream inputStream = file.getInputStream(current))
InputStream inputStream = file.getInputStream(current))
{
outputFile.getParentFile().mkdirs();
NotifyingIOUtils.copy(inputStream, bos,
Expand Down

0 comments on commit b0e83d7

Please sign in to comment.