Example #1
0
  static {
    try {
      String platform;
      if (isWindows()) {
        platform = "windows";
      } else if (isUnix()) {
        platform = "linux";
      } else if (isMac()) {
        platform = "mac";
      } else {
        platform = null;
      }

      String propertiesFile = "undefined";
      if (platform != null) {
        propertiesFile = "org/python/pydev/core/TestDependent." + platform + ".properties";
        InputStream stream =
            TestDependent.class.getClassLoader().getResourceAsStream(propertiesFile);
        if (stream != null) {
          // Initialize the static contents of the class.
          String streamContents = REF.getStreamContents(stream, null, null);
          Properties props = PropertiesHelper.createPropertiesFromString(streamContents);
          Map<String, String> map = PropertiesHelper.createMapFromProperties(props);
          Set<Entry<String, String>> entrySet = map.entrySet();
          for (Entry<String, String> entry : entrySet) {
            String key = entry.getKey();
            try {
              Field field = TestDependent.class.getField(key);
              if (field != null) {
                String value = entry.getValue();
                if (!value.equals("null")) {
                  field.set(null, value);
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        } else {
          System.err.println(
              "Could not get stream to: "
                  + propertiesFile
                  + " to initialize TestDependent.java values.");
        }
      }

      // Checking and setting variables that do not exist (if possible).
      if (PYTHON_INSTALL == null) {
        System.err.println(
            "PYTHON_INSTALL variable MUST be set in " + propertiesFile + " to run tests.");
      } else if (!new File(PYTHON_INSTALL).exists()) {
        System.err.println(
            "PYTHON_INSTALL variable points to path that does NOT exist: " + PYTHON_INSTALL);
      }

      if (TEST_PYDEV_BASE_LOC == null) {
        System.err.println(
            "TEST_PYDEV_BASE_LOC variable MUST be set in " + propertiesFile + " to run tests.");
      } else if (!new File(TEST_PYDEV_BASE_LOC).exists()) {
        System.err.println(
            "TEST_PYDEV_BASE_LOC variable points to path that does NOT exist: "
                + TEST_PYDEV_BASE_LOC);
      }

      if (PYTHON_EXE == null) {
        if (isWindows()) {
          PYTHON_EXE = PYTHON_INSTALL + "python.exe";
        } else {
          PYTHON_EXE = PYTHON_INSTALL + "python";
        }
      }
      if (!new File(PYTHON_EXE).exists()) {
        System.err.println("PYTHON_EXE variable points to path that does NOT exist: " + PYTHON_EXE);
      }

      if (PYTHON_LIB == null) {
        PYTHON_LIB = PYTHON_INSTALL + "Lib/";
      }
      if (PYTHON_DLLS == null) {
        PYTHON_DLLS = PYTHON_INSTALL + "DLLs/";
      }
      if (PYTHON_SITE_PACKAGES == null) {
        PYTHON_SITE_PACKAGES = PYTHON_LIB + "site-packages/";
      }
      if (PYTHON_TEST_PACKAGES == null) {
        if (new File(TestDependent.PYTHON_LIB + "test/").exists()) {
          PYTHON_TEST_PACKAGES = TestDependent.PYTHON_LIB + "test/";
        }
      }

      if (TEST_PYSRC_LOC == null) {
        TEST_PYSRC_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests/pysrc/";
      }

      if (TEST_PYSRC_NAVIGATOR_LOC == null) {
        TEST_PYSRC_NAVIGATOR_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests_navigator/pysrc/";
      }

      if (TEST_PYSRC_LOC2 == null) {
        TEST_PYSRC_LOC2 = TEST_PYDEV_BASE_LOC + "org.python.pydev/tests/pysrc2/";
      }

      if (TEST_PYDEV_PLUGIN_LOC == null) {
        TEST_PYDEV_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev/";
      }

      if (TEST_PYDEV_DEBUG_PLUGIN_LOC == null) {
        TEST_PYDEV_DEBUG_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.debug/";
      }

      if (TEST_PYDEV_JYTHON_PLUGIN_LOC == null) {
        TEST_PYDEV_JYTHON_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.jython/";
      }

      if (TEST_PYDEV_PARSER_PLUGIN_LOC == null) {
        TEST_PYDEV_PARSER_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.parser/";
      }

      if (TEST_PYDEV_REFACTORING_PLUGIN_LOC == null) {
        TEST_PYDEV_REFACTORING_PLUGIN_LOC = TEST_PYDEV_BASE_LOC + "org.python.pydev.refactoring/";
      }

      if (TEST_COM_REFACTORING_PYSRC_LOC == null) {
        TEST_COM_REFACTORING_PYSRC_LOC =
            TEST_PYDEV_BASE_LOC + "com.python.pydev.refactoring/tests/pysrcrefactoring/";
      }

    } catch (Exception e) {
      System.err.println(
          "--- Error getting contents to properly initialize TestDependent.java values ---");
      e.printStackTrace();
    }
  }
Example #2
0
 public Double getDouble(String key, Double defValue) {
   return PropertiesHelper.getDouble(map.get(key), defValue);
 }
  /**
   * Updates the current list of {@link Property} instances, held by an {@link
   * Entity#getProperties()} instance, by appending {@link Property} instance(s) of types
   * represented by the {@link PropertiesUpdateHelper#getRelation()} instance
   */
  public void updateProperties() {
    String[] jpaAnnotationTypesArr = null;
    Properties oneEndEntityPropertiesWrapper = null;
    Properties manyEndEntityPropertiesWrapper = null;

    One one = relation.getOne();
    Many many = relation.getMany();

    String oneEndEntityType = one.getType();
    String manyEndEntityType = many.getType();

    String propertyName = null;
    String propertyType = null;
    String genericTypeParameter = null;
    String mappedBy = null;
    String oneToOnePrimaryEntityPropertyName = null;

    String[] addTypesFullNameShortName = null;

    boolean isEntityJPAEnabled = false;

    switch (relationType) {
      case ONE_TO_MANY:
        // Create collectionType property and add it to "one" end
        // entity properties list

        String collectionType = many.getCollectionType();

        // In this case two types needs to be added to the related entity
        // 1. the type of property
        // 2. the type of collection
        // And both of these should be present in import statements
        addTypesFullNameShortName = new String[] {manyEndEntityType, collectionType};

        oneEndEntityPropertiesWrapper = entityFullyQualifiedNamePropertiesMap.get(oneEndEntityType);

        propertyName = PropertiesHelper.createPropertyNameForCollectionTypeRelatedEntity(many);

        propertyType = collectionType;
        genericTypeParameter = manyEndEntityType;

        isEntityJPAEnabled = entityFullyQualifiedNameIsJPAEnabledMap.get(oneEndEntityType);

        if (isEntityJPAEnabled) {
          jpaAnnotationTypesArr =
              new String[] {
                JPAAnnotationsMarkerHelper.getRelationTypeFullyQualifiedName(relationType),
                JPAConstants.CASCADE_ENUM_TYPE
              };

          if (relation.isBidirectional()) {
            mappedBy = PropertiesHelper.createPropertyNameFromTypeName(oneEndEntityType);
          }
        }

        createAndAddProperty(
            CREATE_COLLECTION_TYPE_PROPERTY,
            propertyName,
            propertyType,
            relationType,
            jpaAnnotationTypesArr,
            genericTypeParameter,
            mappedBy,
            oneToOnePrimaryEntityPropertyName,
            oneEndEntityPropertiesWrapper,
            addTypesFullNameShortName);

        break;

      case MANY_TO_ONE:
        // Create "one" end entity type property and add it to
        // "many" end entity properties list

        addTypesFullNameShortName = new String[] {oneEndEntityType};

        manyEndEntityPropertiesWrapper =
            entityFullyQualifiedNamePropertiesMap.get(manyEndEntityType);

        propertyName = PropertiesHelper.createPropertyNameFromTypeName(oneEndEntityType);
        propertyType = oneEndEntityType;

        isEntityJPAEnabled = entityFullyQualifiedNameIsJPAEnabledMap.get(manyEndEntityType);

        if (isEntityJPAEnabled) {
          jpaAnnotationTypesArr =
              new String[] {
                JPAAnnotationsMarkerHelper.getRelationTypeFullyQualifiedName(relationType),
                JPAConstants.CASCADE_ENUM_TYPE
              };
        }

        createAndAddProperty(
            CREATE_PROPERTY,
            propertyName,
            propertyType,
            relationType,
            jpaAnnotationTypesArr,
            genericTypeParameter,
            mappedBy,
            oneToOnePrimaryEntityPropertyName,
            manyEndEntityPropertiesWrapper,
            addTypesFullNameShortName);

        break;

      case ONE_TO_ONE:
        // =============== PRIMARY ENTITY
        // Create "many" end entity type property and add it to
        // "one" end entity properties list
        // The "one" end entity is considered as Primary entity in one-to-one
        // relation and the entity at "many" end is considered as
        // Non-Primary entity.

        addTypesFullNameShortName = new String[] {manyEndEntityType};

        oneEndEntityPropertiesWrapper = entityFullyQualifiedNamePropertiesMap.get(oneEndEntityType);

        propertyName = PropertiesHelper.createPropertyNameFromTypeName(manyEndEntityType);
        propertyType = manyEndEntityType;

        isEntityJPAEnabled = entityFullyQualifiedNameIsJPAEnabledMap.get(oneEndEntityType);

        if (isEntityJPAEnabled) {
          // The Primary entity requires the "cascade" attribute
          // The Primary entity requires javax.persistence.PrimaryKeyJoinColumn annotation
          jpaAnnotationTypesArr =
              new String[] {
                JPAAnnotationsMarkerHelper.getRelationTypeFullyQualifiedName(relationType),
                JPAConstants.CASCADE_ENUM_TYPE,
                JPAConstants.PRIMARY_KEY_JOIN_COLUMN_TYPE
              };
        }

        createAndAddProperty(
            CREATE_PROPERTY,
            propertyName,
            propertyType,
            relationType,
            jpaAnnotationTypesArr,
            genericTypeParameter,
            mappedBy,
            oneToOnePrimaryEntityPropertyName,
            oneEndEntityPropertiesWrapper,
            addTypesFullNameShortName);

        // =============== NON-PRIMARY ENTITY
        // Create "one" end entity type property in "many" end entity
        // and add it to "many" end entity properties list

        addTypesFullNameShortName = new String[] {oneEndEntityType};

        manyEndEntityPropertiesWrapper =
            entityFullyQualifiedNamePropertiesMap.get(manyEndEntityType);

        propertyName = PropertiesHelper.createPropertyNameFromTypeName(oneEndEntityType);
        propertyType = oneEndEntityType;

        isEntityJPAEnabled = entityFullyQualifiedNameIsJPAEnabledMap.get(manyEndEntityType);

        if (isEntityJPAEnabled) {
          // The Non-Primary entity does not require the "cascade" attribute
          // Thus not added the javax.persistence.CascadeType type to
          // jpaAnnotationTypesArr
          jpaAnnotationTypesArr =
              new String[] {
                JPAAnnotationsMarkerHelper.getRelationTypeFullyQualifiedName(relationType)
              };

          // The Non-Primary entity requires the "mappedBy" attribute on
          // the "one" end entity type property added to non-primary
          // entity's current properties list
          mappedBy = PropertiesHelper.createPropertyNameFromTypeName(manyEndEntityType);
        }

        createAndAddProperty(
            CREATE_PROPERTY,
            propertyName,
            propertyType,
            relationType,
            jpaAnnotationTypesArr,
            genericTypeParameter,
            mappedBy,
            oneToOnePrimaryEntityPropertyName,
            manyEndEntityPropertiesWrapper,
            addTypesFullNameShortName);

        if (isEntityJPAEnabled) {
          // =============== NON-PRIMARY ENTITY
          // Add "id" property in "many" end entity with required annotations
          // for making the One-to-One relation work correctly.
          // Example:

          // @Id
          // @Column(name = "booking_id", unique = true, nullable = false)//TODO: this remains in
          // case of Id property for one-to-one non-primary entity
          // @GeneratedValue(generator="foreign")
          // @GenericGenerator(name="foreign", strategy = "foreign", parameters={
          //		@Parameter(name="property",
          // value="<PRIMARY_ENTITY_PROPERTY_NAME_ADDED_IN_NON_PRIMARY_ENTITY>")
          // })
          // private Long id;
          jpaAnnotationTypesArr =
              new String[] {
                JPAConstants.ID_TYPE,
                JPAConstants.GENERATED_VALUE_TYPE,
                HibernateORMConstants.GENERIC_GENERATOR_TYPE,
                HibernateORMConstants.PARAMETER_TYPE
              };

          propertyName = UtilityConstants.ID_PROPERTY_NAME;
          propertyType = UtilityConstants.ID_PROPERTY_DEFAULT_TYPE;
          oneToOnePrimaryEntityPropertyName =
              PropertiesHelper.createPropertyNameFromTypeName(oneEndEntityType);

          createAndAddProperty(
              CREATE_ONE_TO_ONE_RELATED_NON_PRIMARY_ENTITY_ID_PROPERTY,
              propertyName,
              propertyType,
              relationType,
              jpaAnnotationTypesArr,
              genericTypeParameter,
              mappedBy,
              oneToOnePrimaryEntityPropertyName,
              manyEndEntityPropertiesWrapper,
              addTypesFullNameShortName);
        }

        break;
    }
  }
Example #4
0
 public Long getLong(String key, Long defValue) {
   return PropertiesHelper.getLong(map.get(key), defValue);
 }
Example #5
0
 public Boolean getBoolean(String key, Boolean defValue) {
   return PropertiesHelper.getBoolean(map.get(key), defValue);
 }
Example #6
0
 public PropertyMap getMap(String key, PropertyMap defValue) {
   return PropertiesHelper.getMap(map.get(key), defValue);
 }
Example #7
0
 public PropertyList getList(String key, PropertyList defValue) {
   return PropertiesHelper.getList(map.get(key), defValue);
 }
Example #8
0
 public Date getDate(String key, Date defValue) {
   return PropertiesHelper.getDate(map.get(key), defValue);
 }