Author: euluis
Date: 2007-12-21 07:19:39-0800
New Revision: 13970
Modified:
trunk/src_new/org/argouml/kernel/ProfileConfiguration.java
trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java
trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java
Log:
Issue #4885: fixed the problem of ProfileConfiguration always adding the default profiles to open projects. Cleaning-up some style issues and polished the load method code in ProfileConfigurationFilePersister. Improved the TestProjectWithProfiles.
Modified: trunk/src_new/org/argouml/kernel/ProfileConfiguration.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/ProfileConfiguration.java?view=diff&rev=13970&p1=trunk/src_new/org/argouml/kernel/ProfileConfiguration.java&p2=trunk/src_new/org/argouml/kernel/ProfileConfiguration.java&r1=13969&r2=13970
==============================================================================
--- trunk/src_new/org/argouml/kernel/ProfileConfiguration.java (original)
+++ trunk/src_new/org/argouml/kernel/ProfileConfiguration.java 2007-12-21 07:19:39-0800
@@ -81,16 +81,16 @@
*/
public static final ConfigurationKey KEY_DEFAULT_STEREOTYPE_VIEW =
Configuration.makeKey("profiles", "stereotypeView");
-
+
/**
- * The default constructor for this class. Sets the Java profile as the
- * default one and its formating strategy as the default one.
+ * The default constructor for this class. Sets the default profiles as
+ * given by {@link org.argouml.profile.ProfileManager} as the profiles of
+ * the project.
*
* @param project the project that contains this configuration
*/
public ProfileConfiguration(Project project) {
- super(EXTENSION, project);
-
+ super(EXTENSION, project);
for (Profile p : ProfileFacade.getManager().getDefaultProfiles()) {
addProfile(p);
}
@@ -98,6 +98,22 @@
updateStrategies();
}
+ /**
+ * The constructor for pre-defined profile configurations, such as when a
+ * project is read from a saved file.
+ * @param project the project that contains this configuration
+ * @param configuredProfiles the {@link Profile}s that will be the project
+ * profiles
+ */
+ public ProfileConfiguration(Project project,
+ Collection<Profile> configuredProfiles) {
+ super(EXTENSION, project);
+ for (Profile profile : configuredProfiles) {
+ addProfile(profile);
+ }
+ updateStrategies();
+ }
+
private void updateStrategies() {
for (Profile profile : profiles) {
activateFormatingStrategy(profile);
@@ -369,6 +385,14 @@
return null;
}
+ /**
+ * Find all the model elements in the configured {@link Profile}s
+ * of the given meta type.
+ *
+ * @param metaType the meta type of the model elements to find
+ * @return a {@link Collection} containing the model elements that
+ * are of the given meta type
+ */
@SuppressWarnings("unchecked")
public Collection findByMetaType(Object metaType) {
Set elements = new HashSet();
Modified: trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java?view=diff&rev=13970&p1=trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java&p2=trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java&r1=13969&r2=13970
==============================================================================
--- trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java (original)
+++ trunk/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java 2007-12-21 07:19:39-0800
@@ -26,7 +26,6 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -35,9 +34,9 @@
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import org.xml.sax.InputSource;
@@ -64,58 +63,49 @@
* @see org.argouml.persistence.MemberFilePersister#getMainTag()
*/
public String getMainTag() {
- return "profile";
+ return "profile";
}
/*
* @see org.argouml.persistence.MemberFilePersister#load(org.argouml.kernel.Project, java.io.InputStream)
*/
public void load(Project project, InputStream inputStream)
- throws OpenException {
-
- try {
- ProfileConfiguration pc = new ProfileConfiguration(project);
-
- BufferedReader br = new BufferedReader(new InputStreamReader(
- inputStream));
-
- String line = null;
- while (true) {
- line = br.readLine();
- if (line.trim().equals("<profile>")) {
- break;
- }
- }
-
- while (true) {
- line = br.readLine().trim();
+ throws OpenException {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ inputStream));
- if (line.equals("</profile>")) {
- break;
- }
-
- Profile profile = null;
- List<Profile> profiles =
- ProfileFacade.getManager().getRegisteredProfiles();
+ String line = null;
+ while (true) {
+ line = br.readLine();
+ if (line.trim().equals("<profile>")) {
+ break;
+ }
+ }
+ Collection<Profile> profiles = new ArrayList<Profile>();
+ while (true) {
+ line = br.readLine().trim();
+ if (line.equals("</profile>")) {
+ break;
+ }
+
+ Profile profile = null;
- if (line.equals("<userDefined>")) {
+ if (line.equals("<userDefined>")) {
line = br.readLine().trim();
- String fileName = line.substring(line.indexOf(">") + 1,
+ String fileName = line.substring(line.indexOf(">") + 1,
line.indexOf("</")).trim();
// consumes the <model> tag
br.readLine();
-
- File file = new File(fileName);
- StringBuffer xmi = new StringBuffer();
+ StringBuffer xmi = new StringBuffer();
while (true) {
line = br.readLine();
if (line == null || line.contains("</model>")) {
break;
}
-
xmi.append(line + "\n");
}
@@ -123,35 +113,34 @@
profile = new UserDefinedProfile(fileName, model);
// consumes the </userDefined>
- line = br.readLine().trim();
- } else if (line.equals("<plugin>")) {
- String className = br.readLine().trim();
-
- profile = ProfileFacade.getManager()
- .getProfileForClass(className);
-
- line = br.readLine().trim();
- }
-
- if (profile != null) {
- pc.addProfile(profile);
- }
- }
- project.setProfileConfiguration(pc);
- } catch (Exception e) {
- // LOG.error("Exception", e);
- throw new OpenException(e);
- }
+ line = br.readLine().trim();
+ } else if (line.equals("<plugin>")) {
+ String className = br.readLine().trim();
+ profile = ProfileFacade.getManager().getProfileForClass(
+ className);
+ line = br.readLine().trim();
+ }
+
+ if (profile != null) {
+ profiles.add(profile);
+ }
+ }
+ ProfileConfiguration pc = new ProfileConfiguration(project,
+ profiles);
+ project.setProfileConfiguration(pc);
+ } catch (Exception e) {
+ // LOG.error("Exception", e);
+ throw new OpenException(e);
+ }
}
/*
* @see org.argouml.persistence.MemberFilePersister#save(org.argouml.kernel.ProjectMember, java.io.Writer, boolean)
*/
public void save(ProjectMember member, Writer writer, boolean xmlFragment)
- throws SaveException {
-
+ throws SaveException {
PrintWriter w = new PrintWriter(writer);
- saveProjectMember(member, w);
+ saveProjectMember(member, w);
}
/*
Modified: trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java?view=diff&rev=13970&p1=trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java&p2=trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java&r1=13969&r2=13970
==============================================================================
--- trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java (original)
+++ trunk/tests/org/argouml/kernel/TestProjectWithProfiles.java 2007-12-21 07:19:39-0800
@@ -101,24 +101,28 @@
* the UML profile for Java are consistent</li>
* </ol>
*
- * FIXME: this test causes an error when executed in Eclipse with other
- * tests, but, not when it is executed alone. See FIXME: fails here below.
+ * FIXME: fails in eclipse, but, passes in Ant build. Maybe its my launch
+ * configuration that is broken...
*
* @throws Exception when something goes wrong
*/
public void testRemoveProfileWithModelThatRefersToProfile()
throws Exception {
+ // set UML Profile for Java as a default profile
ProfileManager profileManager = ProfileFacade.getManager();
Profile javaProfile = profileManager.getProfileForClass(
"org.argouml.profile.internal.ProfileJava");
if (!profileManager.getDefaultProfiles().contains(javaProfile)) {
profileManager.addToDefaultProfiles(javaProfile);
}
+ // create a new project and assert that it has the UML profile for
+ // Java as part of the project's profile configuration
Project project = ProjectManager.getManager().makeEmptyProject();
assertTrue(project.getProfileConfiguration().getProfiles().contains(
javaProfile));
-
- Object model = project.getModel();
+ // create a dependency from the project's model to the UML profile for
+ // Java
+ Object model = project.getModels().iterator().next();
assertNotNull(model);
Object fooClass = Model.getCoreFactory().buildClass("Foo", model);
Object javaListType = project.findType("List", false);
@@ -129,24 +133,18 @@
getFacade().getOperations(fooClass).iterator().next());
Object returnParam = getFacade().getParameter(barOperation, 0);
assertNotNull(returnParam);
- // TODO: duplicated consistency check
Object returnParamType = getFacade().getType(returnParam);
- assertEquals(getFacade().getName(javaListType),
- getFacade().getName(returnParamType));
- assertEquals(getFacade().getNamespace(javaListType),
- getFacade().getNamespace(returnParamType));
-
+ checkJavaListTypeExistsAndMatchesReturnParamType(project,
+ returnParamType);
+ // remove the Java profile from the project's profile configuration
project.getProfileConfiguration().removeProfile(javaProfile);
- // TODO: duplicated consistency check
- javaListType = project.findType("List", false);
- assertNotNull(javaListType);
+ // assert that the project's model elements that had a dependency to
+ // the UML profile for Java don't get inconsistent
returnParamType = getFacade().getType(returnParam);
- assertEquals(getFacade().getName(javaListType),
- getFacade().getName(returnParamType));
- assertEquals(getFacade().getNamespace(javaListType),
- getFacade().getNamespace(returnParamType));
+ checkJavaListTypeExistsAndMatchesReturnParamType(project,
+ returnParamType);
assertNotNull(project.findType("Foo", false));
-
+ // save the project into a new file
File file = getFileInUsersTemporaryDirectory(
"testRemoveProfileWithModelThatRefersToProfile.zargo");
AbstractFilePersister persister =
@@ -154,25 +152,37 @@
file.getAbsolutePath());
project.setVersion(ApplicationVersion.getVersion());
persister.save(project, file);
-
+ // reopen the project and assert that the Java profile isn't part of
+ // the profile configuration, including the fact that the type
+ // java.util.List isn't found
project = persister.doLoad(file);
project.postLoad();
+ assertFalse(project.getProfileConfiguration().getProfiles().contains(
+ javaProfile));
+ assertNull(project.findType("List", false));
+ // assert that the project's model elements that had a dependency to
+ // the UML profile for Java are consistent
fooClass = project.findType("Foo", false);
- // FIXME: fails here when executed with other tests in Eclipse
assertNotNull(fooClass);
barOperation = getFacade().getOperations(fooClass).iterator().next();
returnParam = getFacade().getParameter(barOperation, 0);
returnParamType = getFacade().getType(returnParam);
- // TODO: duplicated consistency check
- javaListType = project.findType("List", false);
+ // TODO: now this gets weird! AFAIK no special support for this, but,
+ // you see that the information is in the model.
+ assertNotNull(returnParamType);
+ assertEquals("List", getFacade().getName(returnParamType));
+ assertEquals("util", getFacade().getName(
+ getFacade().getNamespace(returnParamType)));
+ }
+
+ private void checkJavaListTypeExistsAndMatchesReturnParamType(
+ Project project, Object returnParamType) {
+ Object javaListType = project.findType("List", false);
assertNotNull(javaListType);
assertEquals(getFacade().getName(javaListType),
getFacade().getName(returnParamType));
- String javaListTypeNamespaceName =
- getFacade().getName(getFacade().getNamespace(javaListType));
- assertEquals(javaListTypeNamespaceName,
- getFacade().getName(
- getFacade().getNamespace(returnParamType)));
+ assertEquals(getFacade().getNamespace(javaListType),
+ getFacade().getNamespace(returnParamType));
}
private static final String SYSPROPNAME_TMPDIR = "java.io.tmpdir";
@@ -185,16 +195,5 @@
testCaseDir.mkdir();
return new File(testCaseDir, fileName);
}
-
- /**
- * TODO: implement.
- *
- * TODO: document my intent.
- */
- public void xtestProfileConfiguration() {
- // Profile Configuration Without A Default Profile
- // Shouldn't Get That Profile When Reopened
- fail("TODO: I noticed that this is happening in manual test.");
- }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.