Skip to content

Commit

Permalink
Fix gradle dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccasc committed Sep 5, 2020
1 parent 20bf8a3 commit 3eff726
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -37,6 +37,7 @@ sourceSets {
srcDirs = ["$projectDir"]
include 'data/**'
include 'images/**'
include 'resources/**'
include 'README.md'
}
}
Expand Down
35 changes: 34 additions & 1 deletion src/io/controller/ImportDataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -100,7 +113,6 @@ public void run() {
@Override
public void onDataParsed(ArrayList<Way> ways, ArrayList<Node> 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 ("\\")? "\\\\": "/");
Expand Down Expand Up @@ -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"));

This comment has been minimized.

Copy link
@simon04

simon04 Sep 6, 2020

Member

A cleaner way would be to use the resources directly without writing them to the filesystem. JOSM provides the CachedFile class, see https://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java#L96 for an example.

This comment has been minimized.

Copy link
@rebeccasc

rebeccasc Sep 7, 2020

Author Member

For ifcModel.setSchemaFile(path) I need a path object type of nio.file.Path. I can get a CachedFile from the resource files and also the full path to it but figured out that Paths.get(...) cannot handle paths to files embedded in a JAR...

This comment has been minimized.

Copy link
@rebeccasc

rebeccasc Sep 7, 2020

Author Member

Probably Paths.get(...) is able to handle it, but not the methods called from ifcModel.setSchemaFile(path).

jar.close();
}
}

}
9 changes: 6 additions & 3 deletions src/io/parser/BIMtoOSMParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3eff726

Please sign in to comment.