From 3eff7260d0f736a48f1e159c2228c3c449a5ed01 Mon Sep 17 00:00:00 2001 From: rebeccasc <65017227+rebeccasc@users.noreply.github.com> Date: Sat, 5 Sep 2020 23:27:40 +0200 Subject: [PATCH] Fix gradle dependency --- build.gradle | 5 +-- src/io/controller/ImportDataController.java | 35 ++++++++++++++++++++- src/io/parser/BIMtoOSMParser.java | 9 ++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 81aee37..917e7c4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "java" id "eclipse" - id("org.openstreetmap.josm").version("0.7.0") + id "org.openstreetmap.josm" version "0.7.0" } sourceCompatibility = 1.8 @@ -24,7 +24,7 @@ dependencies { testImplementation("org.awaitility:awaitility:4.0.2") compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' - compile 'org.opensourcebim:BuildingSMARTLibrary:1.0.9' + packIntoJar("org.opensourcebim:BuildingSMARTLibrary:1.0.9") } archivesBaseName = "indoorhelper" @@ -37,6 +37,7 @@ sourceSets { srcDirs = ["$projectDir"] include 'data/**' include 'images/**' + include 'resources/**' include 'README.md' } } diff --git a/src/io/controller/ImportDataController.java b/src/io/controller/ImportDataController.java index 9f7d314..abb2ea4 100644 --- a/src/io/controller/ImportDataController.java +++ b/src/io/controller/ImportDataController.java @@ -10,9 +10,14 @@ import java.awt.GridBagLayout; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.jar.JarFile; import java.util.logging.FileHandler; import java.util.logging.SimpleFormatter; +import java.util.zip.ZipEntry; import javax.swing.JButton; import javax.swing.JFrame; @@ -23,6 +28,7 @@ import javax.swing.border.EtchedBorder; import org.openstreetmap.josm.actions.JosmAction; +import org.openstreetmap.josm.data.Preferences; import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.gui.MainApplication; @@ -72,6 +78,13 @@ public ImportDataController() { } catch (SecurityException | IOException e) { Logging.info(e.getMessage()); } + + // export resource files from jar to file system used by BuildingSMARTLibrary + try { + exportPluginResource(); + } catch (Exception e) { + Logging.info(e.getMessage()); + } } @Override @@ -100,7 +113,6 @@ public void run() { @Override public void onDataParsed(ArrayList ways, ArrayList nodes) { model.setImportData(ways, nodes); - String layerName = String.format("BIMObject%2d", MainApplication.getLayerManager().getLayers().size()); if(importedFilepath != null) { String[] parts = importedFilepath.split(File.separator.equals ("\\")? "\\\\": "/"); @@ -160,4 +172,25 @@ private void addInfoLabel() { if(map != null) map.addTopPanel(infoPanel); } + /** + * Export resources embedded in jar into file system + * @throws Exception + */ + private void exportPluginResource() throws Exception{ + File jarFile = new File(ImportDataController.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); + String jarPath = Preferences.main().getPluginsDirectory().toString(); + if(jarFile.isFile()) { + Logging.info("Copying resource files from jar to file system"); + JarFile jar = new JarFile(jarFile); + ZipEntry ze1 = jar.getEntry("resources/IFC2X3_TC1.exp"); + ZipEntry ze2 = jar.getEntry("resources/IFC4.exp"); + InputStream is1 = jar.getInputStream(ze1); + InputStream is2 = jar.getInputStream(ze2); + new File(jarPath + "/indoorhelper/resources").mkdirs(); + Files.copy(is1, Paths.get(jarPath + "/indoorhelper/resources/IFC2X3_TC1.exp")); + Files.copy(is2, Paths.get(jarPath + "/indoorhelper/resources/IFC4.exp")); + jar.close(); + } + } + } diff --git a/src/io/parser/BIMtoOSMParser.java b/src/io/parser/BIMtoOSMParser.java index df8b1e3..7ce7c2a 100644 --- a/src/io/parser/BIMtoOSMParser.java +++ b/src/io/parser/BIMtoOSMParser.java @@ -17,6 +17,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import org.openstreetmap.josm.data.Preferences; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Tag; @@ -53,8 +54,10 @@ public class BIMtoOSMParser { private final String FLAG_IFC2X3_TC1 = "FILE_SCHEMA(('IFC2X3_TC1'))"; private final String FLAG_IFC2X3 = "FILE_SCHEMA(('IFC2X3'))"; private final String FLAG_IFC4 = "FILE_SCHEMA(('IFC4'))"; - private final String resourcePathDir = System.getProperty("user.dir") + File.separator + "resources" + File.separator; - private String ifcSchemaFilePath = resourcePathDir + "IFC2X3_TC1.exp"; // default + private final String resourcePathDir = Preferences.main().getPluginsDirectory().toString() + "/indoorhelper/resources/"; + private final String IFC2X3_TC1_Schema = "IFC2X3_TC1.exp"; + private final String IFC4_Schema = "IFC4.exp"; + private String ifcSchemaFilePath = resourcePathDir + IFC2X3_TC1_Schema; // default private ImportEventListener importListener; private FileInputStream inputfs = null; @@ -139,7 +142,7 @@ private boolean loadFile(String filepath) { return false; } if(usedIfcSchema.equals(FLAG_IFC4)) { - ifcSchemaFilePath = resourcePathDir + "IFC4.exp"; + ifcSchemaFilePath = resourcePathDir + IFC4_Schema; } // load IFC file