View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * 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 distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.apache.maven.plugin.eclipse.it;
16  
17  import java.io.File;
18  import java.io.FileInputStream;
19  import java.util.Properties;
20  
21  import org.apache.maven.plugin.eclipse.writers.workspace.EclipseWorkspaceWriter;
22  import org.apache.maven.plugin.ide.IdeUtils;
23  import org.codehaus.plexus.PlexusTestCase;
24  import org.codehaus.plexus.util.FileUtils;
25  
26  /**
27   * @version $Id: EclipseWorkspaceIT.java 1190754 2011-10-29 04:26:32Z hboutemy $
28   */
29  public class EclipseWorkspaceIT
30      extends AbstractEclipsePluginIT
31  {
32  
33      private static final String ECLIPSE_JDT_CORE_PREFS_PATH =
34          EclipseWorkspaceWriter.ECLIPSE_CORE_RUNTIME_SETTINGS_DIR + "/"
35              + EclipseWorkspaceWriter.ECLIPSE_JDT_CORE_PREFS_FILE;
36  
37      private static final String ECLIPSE_JDT_UI_PREFS_PATH =
38          EclipseWorkspaceWriter.ECLIPSE_CORE_RUNTIME_SETTINGS_DIR + "/"
39              + EclipseWorkspaceWriter.ECLIPSE_JDT_UI_PREFS_FILE;
40  
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45      }
46  
47      public void testWorkspace01()
48          throws Exception
49      {
50          String projectName = "workspace-01";
51  
52          FileUtils.deleteDirectory( this.getTestWorkspaceWorkDirectory( "add-maven-repo" ) );
53          testWorkspace( projectName, "add-maven-repo" );
54  
55          this.validateM2REPOVar( projectName );
56  
57          File eclipseJDTUIPrefsFile = new File( this.getOutputDirectory( projectName ), ECLIPSE_JDT_UI_PREFS_PATH );
58  
59          assertFalse( eclipseJDTUIPrefsFile.exists() );
60      }
61  
62      public void testWorkspace02()
63          throws Exception
64      {
65          // In this test we purposely do not include
66          // expected/.metatdata/.plugins/org.eclipse.core.runtime.settings/org.eclipse.jdt.core.prefs
67          // The content of that file is heavily depended on the location of the test
68  
69          String projectName = "workspace-02";
70  
71          FileUtils.deleteDirectory( this.getTestWorkspaceWorkDirectory( projectName ) );
72          testWorkspace( projectName );
73  
74          this.validateM2REPOVar( projectName );
75  
76          File eclipseJDTUIPrefsFile = new File( this.getOutputDirectory( projectName ), ECLIPSE_JDT_UI_PREFS_PATH );
77  
78          assertTrue( eclipseJDTUIPrefsFile.exists() );
79  
80      }
81  
82      private void validateM2REPOVar( String projectName )
83          throws Exception
84      {
85          File eclipseJDTCorePrefsFile = new File( this.getOutputDirectory( projectName ), ECLIPSE_JDT_CORE_PREFS_PATH );
86  
87          assertTrue( "Test if workspace properties exists", eclipseJDTCorePrefsFile.exists() );
88  
89          Properties props = new Properties();
90          props.load( new FileInputStream( eclipseJDTCorePrefsFile ) );
91  
92          String M2_REPO = props.getProperty( EclipseWorkspaceWriter.CLASSPATH_VARIABLE_M2_REPO );
93  
94          assertNotNull( "Test M2_REPO has a value", M2_REPO );
95  
96          String expectectLocalRepo =
97              new File( PlexusTestCase.getBasedir(), "target/test-classes/m2repo" ).getCanonicalPath();
98          // comparing repo's all in lower case because windows is case insensitive and settings.xml may have
99          // a repository specified with different case
100         expectectLocalRepo = IdeUtils.fixSeparator( expectectLocalRepo ).toLowerCase();
101         String actualLocalRepo = IdeUtils.fixSeparator( M2_REPO ).toLowerCase();
102         assertEquals( "Test M2_REPO value", expectectLocalRepo, actualLocalRepo );
103 
104     }
105 
106 }