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 1672304 2015-04-09 12:04:28Z khmarbaise $
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 testWorkspace02()
48          throws Exception
49      {
50          // In this test we purposely do not include
51          // expected/.metatdata/.plugins/org.eclipse.core.runtime.settings/org.eclipse.jdt.core.prefs
52          // The content of that file is heavily depended on the location of the test
53  
54          String projectName = "workspace-02";
55  
56          FileUtils.deleteDirectory( this.getTestWorkspaceWorkDirectory( projectName ) );
57          testWorkspace( projectName );
58  
59          this.validateM2REPOVar( projectName );
60  
61          File eclipseJDTUIPrefsFile = new File( this.getOutputDirectory( projectName ), ECLIPSE_JDT_UI_PREFS_PATH );
62  
63          assertTrue( eclipseJDTUIPrefsFile.exists() );
64  
65      }
66  
67      private void validateM2REPOVar( String projectName )
68          throws Exception
69      {
70          File eclipseJDTCorePrefsFile = new File( this.getOutputDirectory( projectName ), ECLIPSE_JDT_CORE_PREFS_PATH );
71  
72          assertTrue( "Test if workspace properties exists", eclipseJDTCorePrefsFile.exists() );
73  
74          Properties props = new Properties();
75          props.load( new FileInputStream( eclipseJDTCorePrefsFile ) );
76  
77          String M2_REPO = props.getProperty( EclipseWorkspaceWriter.CLASSPATH_VARIABLE_M2_REPO );
78  
79          assertNotNull( "Test M2_REPO has a value", M2_REPO );
80  
81          String expectectLocalRepo =
82              new File( PlexusTestCase.getBasedir(), "target/test-classes/m2repo" ).getCanonicalPath();
83          // comparing repo's all in lower case because windows is case insensitive and settings.xml may have
84          // a repository specified with different case
85          expectectLocalRepo = IdeUtils.fixSeparator( expectectLocalRepo ).toLowerCase();
86          String actualLocalRepo = IdeUtils.fixSeparator( M2_REPO ).toLowerCase();
87          assertEquals( "Test M2_REPO value", expectectLocalRepo, actualLocalRepo );
88  
89      }
90  
91  }