Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d127f73f7b7943ee188a8ae6cd134343de716538 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*********************************************************************
 * Copyright (c) 2020 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

package org.eclipse.osee.framework.core.util;

import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

/**
 * @author Baily Roberts
 */
public class ManifestTest {

   @Test
   public void ManifestVersionTest() {
      int pluginIndex = System.getProperty("user.dir").indexOf("plugins");
      String pluginsPath = System.getProperty("user.dir").substring(0, pluginIndex + 8);

      File pluginsRoot = new File(pluginsPath);
      File[] pluginDirs = pluginsRoot.listFiles();
      List<File> hasVersions = new ArrayList<>();
      for (File pluginDir : pluginDirs) {

         if (pluginDir.getAbsolutePath().contains("jms")) {
            continue;
         }
         File manifestDir = new File(pluginDir, "META-INF" + File.separator + "MANIFEST.MF");
         if (checkManifestForVersion(manifestDir)) {
            hasVersions.add(pluginDir);
         }
      }

      assertTrue("The Manifests for following plugins contain at least one version " + hasVersions,
         hasVersions.isEmpty());
   }

   private boolean checkManifestForVersion(File path) {
      if (!path.isFile()) {
         return false;
      }
      try (BufferedReader br = new BufferedReader(new FileReader(path))) {

         String line = br.readLine();
         while (line != null) {
            if (line.contains(";version")) {
               return true;
            }

            line = br.readLine();
         }
      } catch (IOException ex) {
         System.out.println("Exception: " + ex);
      }
      return false;
   }
}

Back to the top