• R/O
  • HTTP
  • SSH
  • HTTPS

tmdmaker: Commit

TMD-Maker(T字形ER図作成ツール)のEclipse Plugin,RCP,Webサイト用


Commit MetaInfo

Revision42e7244769ff61dc8253b5917ec560369c72f5e7 (tree)
Time2018-09-22 15:13:12
Authornakag <nakag@user...>
Commiternakag

Log Message

#38370 Add available extensions to FileImporter.

Change Summary

Incremental Difference

--- a/bundles/jp.osdn.tmdmaker.extensions/src/jp/sourceforge/tmdmaker/model/importer/FileImporter.java
+++ b/bundles/jp.osdn.tmdmaker.extensions/src/jp/sourceforge/tmdmaker/model/importer/FileImporter.java
@@ -48,4 +48,6 @@ public interface FileImporter {
4848 * @return Importer名
4949 */
5050 String getImporterName();
51+
52+ String[] getAvailableExtensions();
5153 }
\ No newline at end of file
--- a/bundles/tmdmaker.csv/src/jp/sourceforge/tmdmaker/importer/impl/AttributeFileImporter.java
+++ b/bundles/tmdmaker.csv/src/jp/sourceforge/tmdmaker/importer/impl/AttributeFileImporter.java
@@ -35,6 +35,7 @@ import jp.sourceforge.tmdmaker.model.importer.FileImporter;
3535 *
3636 */
3737 public class AttributeFileImporter implements FileImporter {
38+ private static final String[] EXTENSION = new String[] {"csv"};
3839
3940 /**
4041 * {@inheritDoc}
@@ -71,4 +72,15 @@ public class AttributeFileImporter implements FileImporter {
7172 return "ファイルからアトリビュートをインポート";
7273 }
7374
75+ /**
76+ *
77+ * {@inheritDoc}
78+ *
79+ * @see jp.sourceforge.tmdmaker.model.importer.FileImporter#getAvailableExtensions()
80+ */
81+ @Override
82+ public String[] getAvailableExtensions() {
83+ return EXTENSION;
84+ }
85+
7486 }
--- a/bundles/tmdmaker.csv/src/jp/sourceforge/tmdmaker/importer/impl/EntityFileImporter.java
+++ b/bundles/tmdmaker.csv/src/jp/sourceforge/tmdmaker/importer/impl/EntityFileImporter.java
@@ -20,7 +20,7 @@ import java.io.FileNotFoundException;
2020 import java.io.FileReader;
2121 import java.io.IOException;
2222 import java.util.ArrayList;
23-import java.util.HashMap;
23+import java.util.LinkedHashMap;
2424 import java.util.List;
2525 import java.util.Map;
2626
@@ -28,6 +28,7 @@ import au.com.bytecode.opencsv.CSVReader;
2828 import jp.sourceforge.tmdmaker.model.AbstractEntityModel;
2929 import jp.sourceforge.tmdmaker.model.Attribute;
3030 import jp.sourceforge.tmdmaker.model.Entity;
31+import jp.sourceforge.tmdmaker.model.EntityType;
3132 import jp.sourceforge.tmdmaker.model.IAttribute;
3233 import jp.sourceforge.tmdmaker.model.Identifier;
3334 import jp.sourceforge.tmdmaker.model.Laputa;
@@ -41,6 +42,8 @@ import jp.sourceforge.tmdmaker.model.parts.ModelName;
4142 *
4243 */
4344 public class EntityFileImporter implements FileImporter {
45+ private static final String[] EXTENSION = new String[] { "csv" };
46+
4447 /**
4548 *
4649 * {@inheritDoc}
@@ -63,7 +66,7 @@ public class EntityFileImporter implements FileImporter {
6366 CSVReader reader = new CSVReader(new BufferedReader(new FileReader(filePath)));
6467 String[] nextLine;
6568 AbstractEntityModel l = null;
66- Map<String, AbstractEntityModel> s = new HashMap<String, AbstractEntityModel>();
69+ Map<String, AbstractEntityModel> s = new LinkedHashMap<String, AbstractEntityModel>();
6770 while ((nextLine = reader.readNext()) != null) {
6871 String entityName = nextLine[0];
6972 String attributeName = "";
@@ -108,12 +111,14 @@ public class EntityFileImporter implements FileImporter {
108111 Identifier identifier = new Identifier(attribute.getName());
109112 ModelName name = new ModelName(model.getName());
110113
111- if (model.isEvent()) {
114+ if (isEvent(model)) {
112115 entity = Entity.ofEvent(name, identifier);
113116 } else {
114117 entity = Entity.ofResource(name, identifier);
115118 }
119+ EntityType type = entity.getEntityType();
116120 model.copyTo(entity);
121+ entity.setEntityType(type);
117122 entity.removeAttribute((Attribute) attribute);
118123 entity.setNotImplement(false);
119124
@@ -122,9 +127,30 @@ public class EntityFileImporter implements FileImporter {
122127 return model;
123128 }
124129
130+ private boolean isEvent(AbstractEntityModel model) {
131+ String eventAttributeName = Entity.getDefaultEventAttributeName(model.getName());
132+ for (IAttribute a : model.getAttributes()) {
133+ if (eventAttributeName.equals(a.getName())) {
134+ return true;
135+ }
136+ }
137+ return false;
138+ }
139+
125140 private Laputa createLaputa(Map<String, AbstractEntityModel> s, String entityName) {
126141 Laputa l = Laputa.of(new ModelName(entityName));
127142 s.put(l.getName(), l);
128143 return l;
129144 }
145+
146+ /**
147+ *
148+ * {@inheritDoc}
149+ *
150+ * @see jp.sourceforge.tmdmaker.model.importer.FileImporter#getAvailableExtensions()
151+ */
152+ @Override
153+ public String[] getAvailableExtensions() {
154+ return EXTENSION;
155+ }
130156 }
--- a/bundles/tmdmaker/src/jp/sourceforge/tmdmaker/ui/actions/FileImportAction.java
+++ b/bundles/tmdmaker/src/jp/sourceforge/tmdmaker/ui/actions/FileImportAction.java
@@ -64,7 +64,7 @@ public class FileImportAction extends Action {
6464 .getFigure();
6565 Point p = viewport.getViewLocation();
6666 FileDialog dialog = new FileDialog(viewer.getControl().getShell());
67-
67+ dialog.setFilterExtensions(importer.getAvailableExtensions());
6868 String filePath = dialog.open();
6969 if (filePath != null) {
7070 try {
--- a/docs/tmdmaker.doc/pom.xml
+++ b/docs/tmdmaker.doc/pom.xml
@@ -98,6 +98,12 @@
9898 <version>${release-version}-SNAPSHOT</version>
9999 <scope>test</scope>
100100 </dependency>
101+ <dependency>
102+ <groupId>tmdmaker</groupId>
103+ <artifactId>jp.osdn.tmdmaker.csv.test</artifactId>
104+ <version>${release-version}-SNAPSHOT</version>
105+ <scope>test</scope>
106+ </dependency>
101107 </dependencies>
102108
103109 <build>
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.classpath
@@ -0,0 +1,15 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<classpath>
3+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+ <attributes>
5+ <attribute name="maven.pomderived" value="true"/>
6+ </attributes>
7+ </classpathentry>
8+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
9+ <classpathentry kind="src" path="src/">
10+ <attributes>
11+ <attribute name="test" value="true"/>
12+ </attributes>
13+ </classpathentry>
14+ <classpathentry kind="output" path="target/classes"/>
15+</classpath>
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.project
@@ -0,0 +1,34 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<projectDescription>
3+ <name>jp.osdn.tmdmaker.csv.test</name>
4+ <comment></comment>
5+ <projects>
6+ </projects>
7+ <buildSpec>
8+ <buildCommand>
9+ <name>org.eclipse.jdt.core.javabuilder</name>
10+ <arguments>
11+ </arguments>
12+ </buildCommand>
13+ <buildCommand>
14+ <name>org.eclipse.pde.ManifestBuilder</name>
15+ <arguments>
16+ </arguments>
17+ </buildCommand>
18+ <buildCommand>
19+ <name>org.eclipse.pde.SchemaBuilder</name>
20+ <arguments>
21+ </arguments>
22+ </buildCommand>
23+ <buildCommand>
24+ <name>org.eclipse.m2e.core.maven2Builder</name>
25+ <arguments>
26+ </arguments>
27+ </buildCommand>
28+ </buildSpec>
29+ <natures>
30+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
31+ <nature>org.eclipse.pde.PluginNature</nature>
32+ <nature>org.eclipse.jdt.core.javanature</nature>
33+ </natures>
34+</projectDescription>
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
1+eclipse.preferences.version=1
2+encoding/<project>=UTF-8
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
1+eclipse.preferences.version=1
2+line.separator=\n
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
1+eclipse.preferences.version=1
2+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+org.eclipse.jdt.core.compiler.compliance=1.8
5+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8+org.eclipse.jdt.core.compiler.release=disabled
9+org.eclipse.jdt.core.compiler.source=1.8
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
1+activeProfiles=
2+eclipse.preferences.version=1
3+resolveWorkspaceProjects=true
4+version=1
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
1+Manifest-Version: 1.0
2+Bundle-ManifestVersion: 2
3+Bundle-Name: TMD-Maker CSV Test
4+Bundle-SymbolicName: jp.osdn.tmdmaker.csv.test
5+Bundle-Version: 0.7.0.qualifier
6+Fragment-Host: tmdmaker.csv;bundle-version="0.7.0"
7+Automatic-Module-Name: jp.osdn.tmdmaker.csv.test
8+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9+Bundle-Vendor: TMD-Maker Project
10+Require-Bundle: org.junit
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/build.properties
@@ -0,0 +1,4 @@
1+source.. = src/
2+output.. = target/classes/
3+bin.includes = META-INF/,\
4+ .
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/pom.xml
@@ -0,0 +1,17 @@
1+<project xmlns="http://maven.apache.org/POM/4.0.0"
2+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+ <modelVersion>4.0.0</modelVersion>
5+ <artifactId>jp.osdn.tmdmaker.csv.test</artifactId>
6+ <packaging>eclipse-test-plugin</packaging>
7+
8+ <name>TMD-Maker CSV Test Plugin</name>
9+ <description>TMD-MakerのCSVインポートプロジェクトのテスト用プロジェクト</description>
10+
11+ <parent>
12+ <groupId>tmdmaker</groupId>
13+ <artifactId>jp.osdn.tmdmaker.tests</artifactId>
14+ <version>0.7.0-SNAPSHOT</version>
15+ </parent>
16+
17+</project>
\ No newline at end of file
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/src/jp/sourceforge/tmdmaker/importer/impl/AttributeFileImporterTest.java
@@ -0,0 +1,78 @@
1+/*
2+ * Copyright 2009-2018 TMD-Maker Project <http://tmdmaker.osdn.jp/>
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package jp.sourceforge.tmdmaker.importer.impl;
17+
18+import static org.junit.Assert.assertEquals;
19+
20+import java.io.File;
21+import java.io.FileWriter;
22+import java.io.PrintWriter;
23+import java.util.List;
24+
25+import org.junit.After;
26+import org.junit.Before;
27+import org.junit.Test;
28+
29+import jp.sourceforge.tmdmaker.model.AbstractEntityModel;
30+
31+/**
32+ * AttributeFileImporterのテストクラス.
33+ *
34+ * @author nakag
35+ *
36+ */
37+public class AttributeFileImporterTest {
38+ private File testFile;
39+ private AttributeFileImporter importer;
40+
41+ @Before
42+ public void setUp() throws Throwable {
43+ importer = new AttributeFileImporter();
44+ testFile = File.createTempFile("test", "csv");
45+ try (PrintWriter w = new PrintWriter(new FileWriter(testFile))) {
46+ w.println("テスト1");
47+ w.println("テスト2");
48+ w.println("テスト3");
49+ w.flush();
50+ }
51+ }
52+
53+ @After
54+ public void tearDown() {
55+ if (testFile != null) {
56+ testFile.delete();
57+ }
58+ }
59+
60+ @Test
61+ public void test() throws Throwable {
62+ List<AbstractEntityModel> entities = importer.importEntities(testFile.getAbsolutePath());
63+ assertEquals(1, entities.size());
64+
65+ AbstractEntityModel model = entities.get(0);
66+ assertEquals(3, model.getAttributes().size());
67+ }
68+
69+ @Test
70+ public void testExtension() {
71+ assertEquals("csv", importer.getAvailableExtensions()[0]);
72+ }
73+
74+ @Test
75+ public void testName() {
76+ assertEquals("ファイルからアトリビュートをインポート", importer.getImporterName());
77+ }
78+}
--- /dev/null
+++ b/tests/jp.osdn.tmdmaker.csv.test/src/jp/sourceforge/tmdmaker/importer/impl/EntityFileImporterTest.java
@@ -0,0 +1,89 @@
1+/*
2+ * Copyright 2009-2018 TMD-Maker Project <http://tmdmaker.osdn.jp/>
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package jp.sourceforge.tmdmaker.importer.impl;
17+
18+import static org.junit.Assert.assertEquals;
19+import static org.junit.Assert.assertTrue;
20+
21+import java.io.File;
22+import java.io.FileWriter;
23+import java.io.PrintWriter;
24+import java.util.List;
25+
26+import org.junit.After;
27+import org.junit.Before;
28+import org.junit.Test;
29+
30+import jp.sourceforge.tmdmaker.model.AbstractEntityModel;
31+import jp.sourceforge.tmdmaker.model.Entity;
32+
33+/**
34+ * EntityFileImporterのテストクラス.
35+ *
36+ * @author nakag
37+ *
38+ */
39+public class EntityFileImporterTest {
40+ private File testFile;
41+ private EntityFileImporter importer;
42+
43+ @Before
44+ public void setUp() throws Exception {
45+ importer = new EntityFileImporter();
46+ testFile = File.createTempFile("test", "csv");
47+ try (PrintWriter w = new PrintWriter(new FileWriter(testFile))) {
48+ w.println("テスト1,アトリビュート1");
49+ w.println("テスト1,アトリビュート2");
50+ w.println("テスト2,テスト2番号");
51+ w.println("テスト2,テスト2名称");
52+ w.println("テスト3,テスト3ID");
53+ w.println("テスト3,テスト3日");
54+ w.flush();
55+ }
56+ }
57+
58+ @After
59+ public void tearDown() throws Exception {
60+ if (testFile != null) {
61+ testFile.delete();
62+ }
63+ }
64+
65+ @Test
66+ public void test() throws Throwable {
67+ List<AbstractEntityModel> entities = importer.importEntities(testFile.getAbsolutePath());
68+ assertEquals(3, entities.size());
69+
70+ assertEquals(2, entities.get(0).getAttributes().size());
71+
72+ assertEquals(1, entities.get(1).getAttributes().size());
73+ assertTrue(((Entity) entities.get(1)).isResource());
74+
75+ assertEquals(1, entities.get(2).getAttributes().size());
76+ assertTrue(((Entity) entities.get(2)).isEvent());
77+ }
78+
79+ @Test
80+ public void testExtension() {
81+ assertEquals("csv", importer.getAvailableExtensions()[0]);
82+ }
83+
84+ @Test
85+ public void testName() {
86+ assertEquals("ファイルからエンティティをインポート", importer.getImporterName());
87+ }
88+
89+}
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -18,5 +18,16 @@
1818 <module>tmdmaker.serializer.test</module>
1919 <module>tmdmaker.test</module>
2020 <module>tmdmaker.ui.test</module>
21+ <module>jp.osdn.tmdmaker.csv.test</module>
2122 </modules>
23+
24+ <build>
25+ <plugins>
26+ <plugin>
27+ <groupId>org.jacoco</groupId>
28+ <artifactId>jacoco-maven-plugin</artifactId>
29+ </plugin>
30+ </plugins>
31+ </build>
32+
2233 </project>
\ No newline at end of file
--- a/tests/tmdmaker.core.test/pom.xml
+++ b/tests/tmdmaker.core.test/pom.xml
@@ -13,12 +13,4 @@
1313 <version>0.7.0-SNAPSHOT</version>
1414 </parent>
1515
16- <build>
17- <plugins>
18- <plugin>
19- <groupId>org.jacoco</groupId>
20- <artifactId>jacoco-maven-plugin</artifactId>
21- </plugin>
22- </plugins>
23- </build>
2416 </project>
\ No newline at end of file
--- a/tests/tmdmaker.serializer.test/pom.xml
+++ b/tests/tmdmaker.serializer.test/pom.xml
@@ -13,12 +13,4 @@
1313 <version>0.7.0-SNAPSHOT</version>
1414 </parent>
1515
16- <build>
17- <plugins>
18- <plugin>
19- <groupId>org.jacoco</groupId>
20- <artifactId>jacoco-maven-plugin</artifactId>
21- </plugin>
22- </plugins>
23- </build>
2416 </project>
\ No newline at end of file
--- a/tests/tmdmaker.test/pom.xml
+++ b/tests/tmdmaker.test/pom.xml
@@ -13,12 +13,4 @@
1313 <version>0.7.0-SNAPSHOT</version>
1414 </parent>
1515
16- <build>
17- <plugins>
18- <plugin>
19- <groupId>org.jacoco</groupId>
20- <artifactId>jacoco-maven-plugin</artifactId>
21- </plugin>
22- </plugins>
23- </build>
2416 </project>
\ No newline at end of file
--- a/tests/tmdmaker.ui.test/pom.xml
+++ b/tests/tmdmaker.ui.test/pom.xml
@@ -1,9 +1,13 @@
1-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1+<project xmlns="http://maven.apache.org/POM/4.0.0"
2+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34 <modelVersion>4.0.0</modelVersion>
45 <artifactId>tmdmaker.ui.test</artifactId>
56 <packaging>eclipse-test-plugin</packaging>
67
8+ <name>TMD-Maker UI Test Plugin</name>
9+ <description>TMD-MakerのUIテスト用プロジェクト</description>
10+
711 <parent>
812 <groupId>tmdmaker</groupId>
913 <artifactId>jp.osdn.tmdmaker.tests</artifactId>
@@ -15,25 +19,8 @@
1519 <plugin>
1620 <groupId>org.eclipse.tycho</groupId>
1721 <artifactId>tycho-surefire-plugin</artifactId>
18-
19-<!-- <version>${tycho-version}</version>
20- <configuration>
21- <useUIHarness>true</useUIHarness>
22- <useUIThread>false</useUIThread>
23- <argLine>${tycho.testArgLine} -Xms40m -Xmx1G ${os-jvm-flags}</argLine>
24- <appArgLine>-nl en</appArgLine>
25- <product>org.eclipse.platform.ide</product>
26- <application>org.eclipse.ui.ide.workbench</application>
27- </configuration>
28- --> </plugin>
29-
30- <plugin>
31- <groupId>org.jacoco</groupId>
32- <artifactId>jacoco-maven-plugin</artifactId>
3322 </plugin>
3423 </plugins>
3524 </build>
36- <description>TMD-MakerのUIテスト用プロジェクト</description>
37- <name>TMD-Maker UI Test Plugin</name>
3825
3926 </project>
\ No newline at end of file
Show on old repository browser